diff --git a/src/corelib/global/qnamespace.qdoc b/src/corelib/global/qnamespace.qdoc index a393b30f892..64da69c0ac1 100644 --- a/src/corelib/global/qnamespace.qdoc +++ b/src/corelib/global/qnamespace.qdoc @@ -96,7 +96,10 @@ \value AA_DontShowIconsInMenus Actions with the Icon property won't be shown in any menus unless specifically set by the - QAction::iconVisibleInMenu property. + QAction::iconVisibleInMenu property. The default value of this + attribute depends on the platform. To override the default + behavior, set the attribute after QGuiApplication has been + instantiated. Menus that are currently open or menus already created in the native \macos menubar \e{may not} pick up a change in this attribute. Changes in the QAction::iconVisibleInMenu property will always be picked up. diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index 35f7ec12bfd..1768cd8aa1a 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -538,8 +538,10 @@ QList QAction::associatedObjects() const \brief the action's icon In toolbars, the icon is used as the tool button icon; in menus, - it is displayed to the left of the menu text. There is no default - icon. + it is displayed to the left of the menu text, as long as + QAction::iconVisibleInMenu returns \c true. + + There is no default icon. If a null icon (QIcon::isNull()) is passed into this function, the icon of the action is cleared. diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 9ef61ef4fa8..f11193055e1 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1396,6 +1396,11 @@ static void init_platform(const QString &pluginNamesWithArguments, const QString fontSmoothingGamma = platformIntegration->styleHint(QPlatformIntegration::FontSmoothingGamma).toReal(); QCoreApplication::setAttribute(Qt::AA_DontShowShortcutsInContextMenus, !QGuiApplication::styleHints()->showShortcutsInContextMenus()); + + if (const auto *platformTheme = QGuiApplicationPrivate::platformTheme()) { + QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, + !platformTheme->themeHint(QPlatformTheme::ShowIconsInMenus).toBool()); + } } static void init_plugins(const QList &pluginList) diff --git a/src/gui/kernel/qplatformtheme.cpp b/src/gui/kernel/qplatformtheme.cpp index 3d1319615ed..f298cadae6b 100644 --- a/src/gui/kernel/qplatformtheme.cpp +++ b/src/gui/kernel/qplatformtheme.cpp @@ -652,6 +652,8 @@ QVariant QPlatformTheme::defaultThemeHint(ThemeHint hint) return QVariant(QSize(16, 16)); case UnderlineShortcut: return true; + case ShowIconsInMenus: + return true; } return QVariant(); diff --git a/src/gui/kernel/qplatformtheme.h b/src/gui/kernel/qplatformtheme.h index d007a196757..3ce094d85b3 100644 --- a/src/gui/kernel/qplatformtheme.h +++ b/src/gui/kernel/qplatformtheme.h @@ -97,6 +97,7 @@ public: MouseCursorTheme, MouseCursorSize, UnderlineShortcut, + ShowIconsInMenus, }; Q_ENUM(ThemeHint) diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index f3f3e05b502..1623b12be63 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -464,6 +464,8 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const return NSEvent.keyRepeatDelay * 1000; case QPlatformTheme::KeyboardAutoRepeatRate: return 1.0 / NSEvent.keyRepeatInterval; + case QPlatformTheme::ShowIconsInMenus: + return false; default: break; }