I am developing an application for Android/iOS.
I am using MouseArea to make my button.
I am stuck in the following case:
Touch on screen with 4 fingers, 1 finger among them touch on the button.
Swipe the screen.
The application become inactive state. I display a item as a popup (the button will go into disabled state) when the application become active state again. Then the popup will be hidden, the button is enabled state.
Now the button doesn't receive mouse event again.
Solution:
I override notify method of QGuiApplication:
bool MyApplication::notify(QObject *receiver, QEvent *event){
QEvent::Type t = event->type();
switch(t){
case QEvent::MouseButtonPress:{
QString classname(receiver ->metaObject()->className());
lastReceiver = receiver;
}
break;
case QEvent::MouseButtonRelease:
lastReceiver = NULL;
break;
case QEvent::ApplicationStateChange:
//To background
if (lastReceiver != NULL){
QQuickItem*item = qobject_cast< QQuickItem*>(lastReceiver);
if (item != NULL){
if(QGuiApplication::applicationState() == Qt::ApplicationInactive){
item ->ungrabMouse();
}
if(QGuiApplication::applicationState() == Qt::ApplicationActive ){
item ->grabMouse();
lastReceiver = NULL;
}
}
}
break;
default:
break;
}
return QGuiApplication::notify(receiver,event);
}
Không có nhận xét nào:
Đăng nhận xét