From 02a5580292ed503b1a830b1831b3f0274b600cef Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 27 May 2021 10:58:26 +0200 Subject: [PATCH] macOS: allow Qt::AA_DontShowShortcutsInContextMenus overrides MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following the discussion in QTBUG-69452, the resulting change in cc33dd079796437bafed8f42de7fbf8f17d19ec8, and the documentation of QAction::shortcutVisibleInContextMenu, the intention is that the attribute allows the overriding of the platform default. However, QAction did ask both the attribute and the platform integration, making the override impossible. Instead, ask only the attribute, but default the value of the attribute to what the platform integration provides. [ChangeLog][QtGui][QAction] The shortcutVisibleInContextMenu property defaults to the value of the Qt::AA_DontShowShortcutsInContextMenus attribute, which in turn defaults to the platform integration. To override the default, set the application attribute after instantiating QApplication, or override the default for each QAction instance. Task-number: QTBUG-73990 Change-Id: Iaba330913555d93d05efe1b3965a6aea39db5554 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Tor Arne Vestbø (cherry picked from commit 68297195759492594ac4143b7f208e17fe6f594b) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/global/qnamespace.qdoc | 4 +++- src/gui/kernel/qaction.cpp | 9 +++------ src/gui/kernel/qguiapplication.cpp | 5 ++++- src/widgets/widgets/qlineedit.cpp | 3 +-- src/widgets/widgets/qwidgettextcontrol.cpp | 3 +-- 5 files changed, 12 insertions(+), 12 deletions(-) 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())