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

Mac - Native menu bar, clicking on a submenu should not trigger QMenu::triggered(QAction*) signal

    XMLWordPrintable

Details

    • macOS

    Description

      On Windows and Mac with non native menu bar, the QMenu::triggered signal is not emitted - as expected.
      On Mac when using the native menu bar, QMenu::triggered is triggered - not expected

      Example to reproduce the issue:

      #include <QtGui>
      
      class Window : public QMainWindow
      {
          Q_OBJECT
      public:
          Window()
          {
              menuBar()->setNativeMenuBar(true);
              QMenu* menu = new QMenu("Menu");
              QMenu* subMenu = new QMenu("SubMenu");
              menu->addMenu(subMenu);//->setProperty("toignore", true);
              menu->addAction("Item2");
              connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onMenuBarTriggered(QAction*)));
              menuBar()->addMenu(menu);
          }
      
      public slots:
          void onMenuBarTriggered(QAction* action)
          {
              //if (!action->property("toignore").toBool())
                  QMessageBox::information(this, "Menu triggered", action->text());
          }
      };
      
      int main(int argc, char* argv[])
      {
          QApplication app(argc, argv);
          Window* w = new Window;
          w->show();
          return app.exec();
      }
      
      #include "main.moc"
      

      Suggested workaround:
      Setting a property to be able to ignore the code when the slot is triggered

      Tested with Cocoa

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            6 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes