Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-8573

Mac OS X: QMenu steals all mouse press events while it is open

    XMLWordPrintable

Details

    • macOS

    Description

      When a QMenu is open, it steals all mouse events, even ones that occur outside the bounds of the menu. As a result, right-clicking outside of the QMenu simply closes the menu, but does not pass the mousePressEvent on to the widget actually under the mouse. This behavior is inconsistent with all other OSX applications – right-clicking outside of a context menu should both close the menu AND popup a new one in the new location. This example demonstrates the problem:

      #include <QtGui>
      
      class MyMenu : public QMenu {
      public:
      	MyMenu(QWidget *parent=0) : QMenu(parent) {}
      protected:
      	void mousePressEvent(QMouseEvent *e) {
      		qDebug("MyMenu mouse press");
      		QMenu::mousePressEvent(e);
      	}
      };
      
      class MyWidget : public QWidget {
      protected:
      	void mousePressEvent(QMouseEvent *e) {
      		qDebug("MyWidget mouse press");
      		QWidget::mousePressEvent(e);
      	}
      	void contextMenuEvent(QContextMenuEvent *e) {
      		MyMenu menu(this);
      		menu.addAction("foo");
      		menu.exec(e->globalPos());
      	}
      };
      
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          MyWidget w;
          w.show();
          return a.exec();
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sorvig Morten Sørvig
            jugdish Jugdish
            Votes:
            4 Vote for this issue
            Watchers:
            13 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes