diff options
authorRichard Moe Gustavsen <>2019-05-09 12:46:15 +0200
committerRichard Moe Gustavsen <>2019-05-15 11:40:12 +0000
commitcc33dd079796437bafed8f42de7fbf8f17d19ec8 (patch)
parent16eb2b7e327c48e04bb7306c79cf45f9b843cff8 (diff)
QMenu: show shortcuts in context menus by default
Change c2c3452ba introduced a new API in Qt to let QPA inform whether or not shortcuts should be shown in context menus. This was set to false by default, since by observation, this seemed to be the most common behavior across platforms. The problem is that it left no way for the application to override it; The attribute Qt::AA_DontShowShortcutsInContextMenus simply doesn't work when shortcuts are always off. And for some application, showing shortcuts is not just a matter of look-and-feel, but also important information to be able to use the application the way intended. This patch reverts the behavior back to how it was in Qt-5.9, where shortcuts where shown by default (except on macOS where we still keep them off). It's no so much because the "always off" logic is wrong, but because there is no (easy) way/work-around for an app developer to switch them back on (until Qt-5.13, where a new API is introduced to fix the situation: b1a9a77). And this lack of API can be a show-stopper for some when upgrading from e.g 5.9 LTS to 5.12 LTS. This downside of this patch, OTOH, is that it can cause more change that what is normally wanted in a patch release. But out of two evils, this is the best option. Those that wan't to hide shortcuts can set AA_DontShowShortcutsInContextMenus to true, which now will work. [ChangeLog][QtWidgets][QMenu] Shortcuts are again shown by default in context menus, except on macOS. They can be forced off by setting AA_DontShowShortcutsInContextMenus to true. Fixes: QTBUG-69452 Change-Id: Ibcc371395944ac5b19b1d20889940da271bf73d5 Reviewed-by: Tor Arne Vestbø <> Reviewed-by: Friedemann Kleint <> Reviewed-by: Frederik Gladhorn <>
2 files changed, 9 insertions, 2 deletions
diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp
index 277d976dde..f906f808d8 100644
--- a/src/gui/kernel/qplatformtheme.cpp
+++ b/src/gui/kernel/qplatformtheme.cpp
@@ -471,6 +471,8 @@ QVariant QPlatformTheme::themeHint(ThemeHint hint) const
return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ItemViewActivateItemOnSingleClick);
case QPlatformTheme::UiEffects:
return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::UiEffects);
+ case QPlatformTheme::ShowShortcutsInContextMenus:
+ return QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::ShowShortcutsInContextMenus);
return QPlatformTheme::defaultThemeHint(hint);
@@ -521,7 +523,7 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint)
case QPlatformTheme::StyleNames:
return QVariant(QStringList());
case QPlatformTheme::ShowShortcutsInContextMenus:
- return QVariant(false);
+ return QVariant(true);
case TextCursorWidth:
return QVariant(1);
case DropShadow:
diff --git a/src/plugins/platforms/cocoa/ b/src/plugins/platforms/cocoa/
index fb3d05d3e4..cbbf6b115e 100644
--- a/src/plugins/platforms/cocoa/
+++ b/src/plugins/platforms/cocoa/
@@ -490,8 +490,13 @@ QCocoaServices *QCocoaIntegration::services() const
QVariant QCocoaIntegration::styleHint(StyleHint hint) const
- if (hint == QPlatformIntegration::FontSmoothingGamma)
+ switch (hint) {
+ case FontSmoothingGamma:
return QCoreTextFontEngine::fontSmoothingGamma();
+ case ShowShortcutsInContextMenus:
+ return QVariant(false);
+ default: break;
+ }
return QPlatformIntegration::styleHint(hint);