Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QMenu: blocking mouse right button click...

QMenu: blocking mouse right button click...

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 562 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sitesvS Offline
    sitesvS Offline
    sitesv
    wrote on last edited by sitesv
    #1

    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;
    }
    
    1 Reply Last reply
    0
    • sitesvS Offline
      sitesvS Offline
      sitesv
      wrote on last edited by
      #2

      Some ideas?

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        Try also check event->type() for
        QEvent::MouseButtonDblClick

        1 Reply Last reply
        0
        • sitesvS Offline
          sitesvS Offline
          sitesv
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved