From 0e2ab08121a357a9ae82335cc51b0deb96ba58ba Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 23 Dec 2020 07:17:57 +0800 Subject: [PATCH] Gui: temporary fix of preference menu in macos QAction defaults menu role to TextHeuristicRole, which causes qt to guess the menu role based on action title. And titles start with 'Config', 'Options', 'Settings', etc. will be considered as preference menu. It seems some non-english translation causes the wrong action be chosen as preference, such as 'Treeview actions'. This commit just applied a temporary fix to default to QAction::NoRole for GroupCommand. If there is ever some GroupCommand need to be a system menu item on macos, we could add some command bit flag for that purpose. --- src/Gui/Action.cpp | 6 ++++-- src/Gui/Command.cpp | 1 + src/Gui/CommandStd.cpp | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index cbc94c304a..cdc92643d1 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -252,8 +252,10 @@ void ActionGroup::addTo(QWidget *w) // and adding this action to the widget doesn't work. if (_dropDown) { if (w->inherits("QMenu")) { - QMenu* menu = qobject_cast(w); - menu = menu->addMenu(_action->text()); + QMenu *menu = new QMenu(w); + QAction* action = qobject_cast(w)->addMenu(menu); + action->setMenuRole(_action->menuRole()); + menu->setTitle(_action->text()); menu->addActions(_group->actions()); } else if (w->inherits("QToolBar")) { diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index 983f423b6d..e5a735232b 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -995,6 +995,7 @@ Command *GroupCommand::addCommand(const char *name) { Action * GroupCommand::createAction(void) { ActionGroup* pcAction = new ActionGroup(this, getMainWindow()); + pcAction->setMenuRole(QAction::NoRole); pcAction->setDropDownMenu(true); pcAction->setExclusive(false); pcAction->setCheckable(true); diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index e3551d2375..0a6698f08e 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -377,6 +377,7 @@ Action * StdCmdDlgPreferences::createAction(void) { Action *pcAction = Command::createAction(); pcAction->setMenuRole(QAction::PreferencesRole); + return pcAction; }