Eventfilter gets form instead of label
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
Re: Eventfilter gets form instead of label
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
Re: Eventfilter gets form instead of label
Maybe just filter out context menu events coming from QMainWindow or other widgets that you do not support.
Code:
{
if( o
== && e
->type
() == QEvent::ContextMenu ) {
return true;
}
}
Re: Eventfilter gets form instead of label
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.