QMenu: blocking mouse right button click...
Solved
General and Desktop
-
Hi!
I filter the right button click event on QAction button of QMenu by eventFilter...
But the right button double-clicking is performed...
How to block that?I have a misunderstanding of the event filtering process:
I don't know why, but if I press twice the right mouse button, the event of the first click will be blocked, but the slot, connected to the triggered signal, will execute.... QMenu *menu = new QMenu(this); menu->installEventFilter(this); QAction *action = new QAction("Button1", this); connect(action, SIGNAL(triggered()), this, SLOT(onTriggered())); menu->addAction(action); menu->popup(...); ... bool MyClass::eventFilter(QObject *obj, QEvent *event) { bool val = QObject::eventFilter(obj, event); QMenu *menu = dynamic_cast<QMenu*>(obj); if(menu && event->type() == QEvent::MouseButtonPress){ QMouseEvent *mev = dymanic_cast<QMouseEvent*>(event); if(mev->button() == Qt::RightButton){ event->ignore(); return true; } } return val; }
-
Hi
Try also check event->type() for
QEvent::MouseButtonDblClick