summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmenubar.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-04-27 15:24:43 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-05-16 20:09:38 +0200
commit842dbca61716409b30714680c961684811eb97ca (patch)
treef465a9296584d92a46ebac2f83bf0fe3d73bfbb2 /src/widgets/widgets/qmenubar.cpp
parentc33427240f1e7e99a36d4c8fff19975ebe508839 (diff)
macOS: Detect menu bar roles for untranslated menu titles as well
If an application added an "About" menu action, and then loaded the qtbase translations, we would try to match the incoming menu title ("About") against QCoreApplication::translate("QCocoaMenuItem", "About"), which since qtbase provides translation in the QCocoaMenuItem context would fail, and we would not detect the menu item role successfully. For this to work, the application developer would need to add their own translations for every menu item, and these translations would have to match the QCocoaMenuItem translations in qtbase. By also comparing the menu titles against the untranslated heuristics we now account for the situation that the app has not translated its menu items. If the app does add translations of its menu items these still need to match the QCocoaMenuItem context translations. Change-Id: Ic2f019cd42b7e080187f9738840f84b0cec239df Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/widgets/qmenubar.cpp')
-rw-r--r--src/widgets/widgets/qmenubar.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/widgets/widgets/qmenubar.cpp b/src/widgets/widgets/qmenubar.cpp
index a53bc97516..a5c2c894a1 100644
--- a/src/widgets/widgets/qmenubar.cpp
+++ b/src/widgets/widgets/qmenubar.cpp
@@ -596,11 +596,13 @@ void QMenuBar::initStyleOption(QStyleOptionMenuItem *option, const QAction *acti
Qt for \macos also provides a menu bar merging feature to make
QMenuBar conform more closely to accepted \macos menu bar layout.
- The merging functionality is based on string matching the title of
- a QMenu entry. These strings are translated (using QObject::tr())
- in the "QMenuBar" context. If an entry is moved its slots will still
- fire as if it was in the original place. The table below outlines
- the strings looked for and where the entry is placed if matched:
+ If an entry is moved its slots will still fire as if it was in the
+ original place.
+
+ The merging functionality is based on the QAction::menuRole() of
+ the menu entries. If an item has QAction::TextHeuristicRole,
+ the role is determined by string matching the title using the
+ following heuristics:
\table
\header \li String matches \li Placement \li Notes
@@ -618,8 +620,8 @@ void QMenuBar::initStyleOption(QStyleOptionMenuItem *option, const QAction *acti
created to call QCoreApplication::quit()
\endtable
- You can override this behavior by using the QAction::menuRole()
- property.
+ You can override this behavior by setting the QAction::menuRole()
+ property to QAction::NoRole.
If you want all windows in a Mac application to share one menu
bar, you must create a menu bar that does not have a parent.