Issues with eventFilter
-
Need to pick this up again.
The following should filter all MouseEvents while !bTouchActive, i.e. the GUI is hidden in my app. With the code below, the GUI still reflects the touches and another object has the focus after the GUI is turned back on. While the GUI is inactive it currently just should debug the cursor position where it has been touched but not "react" on the GUI. Funny enough, it does change the focus to a different object but it does not execute its press/release MouseEvent.
What is wrong in the code below?@class MyApplication : public QApplication
{
public:
MyApplication(int &argc, char **argv ) : QApplication(argc, argv)
{
}virtual bool notify ( QObject *receiver, QEvent *event ) { switch( event->type() ) { case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseMove: case QEvent::MouseButtonDblClick: { if(bTouchActive) { qDebug("Touch/Mouse event type: %d", event->type()); } else { QMouseEvent *TEvent = static_cast<QMouseEvent *>(event); QPoint cursorPos = TEvent->globalPos(); qDebug("TouchInActive: TouchXpos %d, TouchYpos %d", cursorPos.rx(), cursorPos.ry()); return true; // return with true filters the event } break; } case QEvent::KeyPress: case QEvent::KeyRelease: { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); qDebug("Key %d pressed, Event type: %d", keyEvent->key(), event->type()); break; // break does not filter and forwards the event to notify() } default: break; } QApplication::notify(receiver,event); return false; }
};
@