Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
None
-
5.6.2, 5.9.0 Alpha
-
None
Description
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.
Attachments
Issue Links
- is replaced by
-
QTBUG-104397 [Reg-5.15.2->6.3.0] Menu separators do not collapse after items moved with setMenuRole
-
- Closed
-