Important: Please read the Qt Code of Conduct -

QMenu: blocking mouse right button click...

  • 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);
    QAction *action = new QAction("Button1", this);
    connect(action, SIGNAL(triggered()), this, SLOT(onTriggered()));
    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){
             return true;
       return val;

  • Some ideas?

  • Lifetime Qt Champion

    Try also check event->type() for

  • My problem was with popup() method and dynamic creation of QMenu...
    Changed to exec();

Log in to reply