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

separatorsCollapsible does not work when menu items are moved to the application menu on Mac OS X

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • None
    • 5.6.2, 5.9.0 Alpha
    • QPA
    • None
    • macOS

      I am working on a cross-platform application. We have some code like this:

            // ... set up file menu stuff ...
            fileMenu.addSeparator();
            fileMenu.addAction(&preferencesAction);
            fileMenu.addSeparator();
            fileMenu.addAction(&exitAction);
      

      This looks fine on Windows, but on Mac it results in a file menu ending with 2 separators, as the preferences and exit menu items were moved to the Application menu.
      Explicitly doing fileMenu.setSeparatorsCollapsible(true) does not fix the problem.
      The following code also does not work:

            // ... set up file menu stuff ...
            fileMenu.addAction(&preferencesAction);
            fileMenu.insertSeparator(&preferencesAction);
            fileMenu.addAction(&exitAction);
            fileMenu.insertSeparator(&exitAction);
      

      The following code successfully works around this problem:

            // ... set up file menu stuff ...
            QAction * preferencesSeparator = new QAction(this);
            preferencesSeparator->setSeparator(true);
            preferencesSeparator->setMenuRole(QAction::PreferencesRole);
            fileMenu.addAction(preferencesSeparator);
            fileMenu.addAction(&preferencesAction);
            QAction * exitSeparator = new QAction(this);
            exitSeparator->setSeparator(true);
            exitSeparator->setMenuRole(QAction::QuitRole);
            fileMenu.addAction(exitSeparator);
            fileMenu.addAction(&exitAction);
      

      I recommend both:

      • Fix separatorsCollapsible property so it can deal with menu items being moved on OS X.
      • Change insertSeparator(QAction*) to make the separator inherit the MenuRole of the argument.

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

            vhilshei Volker Hilsheimer
            lukeworth Luke Worth
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes