diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index dd6fccd678b..e1dfc883984 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -118,7 +118,9 @@ \value AA_DontShowShortcutsInContextMenus Actions with the Shortcut property won't be shown in any shortcut menus unless specifically set by the QAction::shortcutVisibleInContextMenu property. This value was added - in Qt 5.10. + in Qt 5.10, and defaults to the preference reported by the implementation + of QPlatformIntegration::styleHint. To override the platform integration, + set this attribute after QCoreApplication has been instantiated. \value AA_NativeWindows Ensures that widgets have native windows. diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index f16cf5d1b7a..781d62c18ac 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -1301,8 +1301,7 @@ bool QAction::isIconVisibleInMenu() const shown via a context menu, when it is false, it is not shown. The default is to follow whether the Qt::AA_DontShowShortcutsInContextMenus attribute - is set for the application, falling back to the widget style hint. - Explicitly setting this property overrides the presence (or abscence) of the attribute. + is set for the application. Explicitly setting this property overrides the attribute. \sa shortcut, QCoreApplication::setAttribute() */ @@ -1323,10 +1322,8 @@ void QAction::setShortcutVisibleInContextMenu(bool visible) bool QAction::isShortcutVisibleInContextMenu() const { Q_D(const QAction); - if (d->shortcutVisibleInContextMenu == -1) { - return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) - && QGuiApplication::styleHints()->showShortcutsInContextMenus(); - } + if (d->shortcutVisibleInContextMenu == -1) + return !QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus); return d->shortcutVisibleInContextMenu; } diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 5bf0bc25c90..fc9f42072ed 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1304,7 +1304,10 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString } #endif - fontSmoothingGamma = QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal(); + const auto platformIntegration = QGuiApplicationPrivate::platformIntegration(); + fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal(); + QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, + !platformIntegration->styleHint(QPlatformIntegration::ShowShortcutsInContextMenus).toBool()); } static void init_plugins(const QList &pluginList) diff --git a/src/widgets/widgets/qlineedit.cpp b/src/widgets/widgets/qlineedit.cpp index 9643c4db433..8c70b8b026d 100644 --- a/src/widgets/widgets/qlineedit.cpp +++ b/src/widgets/widgets/qlineedit.cpp @@ -83,8 +83,7 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include "qkeysequence.h" -#define ACCEL_KEY(k) ((!QCoreApplication::testAttribute(Qt::AA_DontShowIconsInMenus) \ - && QGuiApplication::styleHints()->showShortcutsInContextMenus()) \ +#define ACCEL_KEY(k) (!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) \ && !QGuiApplicationPrivate::instance()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString()) #else diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 2aaba2c4141..2dbf09fc4fe 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -98,8 +98,7 @@ #include "private/qapplication_p.h" #include "private/qshortcutmap_p.h" #include -#define ACCEL_KEY(k) ((!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) \ - && QGuiApplication::styleHints()->showShortcutsInContextMenus()) \ +#define ACCEL_KEY(k) (!QCoreApplication::testAttribute(Qt::AA_DontShowShortcutsInContextMenus) \ && !QGuiApplicationPrivate::instance()->shortcutMap.hasShortcutForKeySequence(k) ? \ QLatin1Char('\t') + QKeySequence(k).toString(QKeySequence::NativeText) : QString())