From 6f26068071ddb381b2ef1d8f65fecf1baa5969b7 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. Fixes realthunder/FreeCAD_Assembly#388 --- src/Gui/Action.cpp | 5 +++-- src/Gui/Command.cpp | 1 + src/Gui/CommandStd.cpp | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 3f7d3d6a2654c..258155395f2b1 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -273,8 +273,9 @@ 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->addActions(_group->actions()); } else if (w->inherits("QToolBar")) { diff --git a/src/Gui/Command.cpp b/src/Gui/Command.cpp index a597bf591988e..db6511b9d6ad9 100644 --- a/src/Gui/Command.cpp +++ b/src/Gui/Command.cpp @@ -1020,6 +1020,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 0830670c10245..aa3c78910604c 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; }