PDA

View Full Version : Eventfilter gets form instead of label



StrikeByte
21st May 2012, 16:21
Hello all,

I'm creating a virtual right mouse button, this is only used in the Qt application. Holding down the left mouse button for 750 msec it will send a ContextMenuEvent. This is usefull for touchscreen users, and not willing to enable global virtual right mouse button.

Now the real problem/challenge
I've made a VirtualRightMouseButton class which installs an eventfilter by using qApp->installEventFilter(...
When i hold the left mouse button on an editbox or some other editor it works perfectly (and opens a context menu), now when i use it on a label it doesn't show a context menu (yes i know it doesn't have a default context menu, so i added an customcontextmenu, when normal right clicking it, it works and shows the custom context menu)
after a while of debugging i found that the eventfilter gets the container class instead of the label (in this case the QMainWindow and not the QLabel) does anyone know why

Thanks in advance.

edit: It also works normally on QButtons

StrikeByte
22nd May 2012, 10:32
I've found the problem myself
When clicking a QLabel there are multiple click events fired
the first is QLabel then the second is the QMainFrame

Spitfire
22nd May 2012, 11:06
Maybe just filter out context menu events coming from QMainWindow or other widgets that you do not support.


bool MainWindow::eventFilter( QObject* o, QEvent* e )
{
if( o == && e->type() == QEvent::ContextMenu )
{
return true;
}
return QMainWindow::eventFilter( o, e );
}

StrikeByte
23rd May 2012, 09:29
Thank you for you're reply Spitfire

The virtual right mouse button needs to filter the left mouse click and check if it is held for 750ms, i don't have to filter the context menu event, this is the even that I send when the mouse is clicked for 750ms.

I've solved it by just filtering out the first mouse down event (leftbutton), the events are fired in order of visibility and the QLable is on top/first.