From 4a738424aaef7958917b92bd64a08eb6208d9c06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 5 Jan 2017 15:01:02 +0100 Subject: Fall back to platform theme in QPlatformSystemTrayIcon::createMenu() Commit 824f08046 introduced QPlatformSystemTrayIcon::createMenu() as a way for platforms to provide a system tray menu independently of the menu created by QPlatformTheme::createPlatformMenu(), which would on some platforms be null. Commit 063997f44ffc then made menu creation lazy, which meant that the logic in QSystemTrayIconPrivate::addPlatformMenu() to create the menu turned from "create menu via QPSTI::createMenu() if QPT::createPlatformMenu() returned null", to "create menu via QPSTI::createMenu() if menu was not created yet". The latter logic relied on each platform having implementations of QPlatformSystemTrayIcon::createMenu() which they didn't, resulting in missing menus for system trays on e.g. macOS. With the new lazy logic, the reasonable approach is for the default implementation of createMenu() to use createPlatformMenu(), which will ensure system tray menus on platforms that implement createPlatformMenu(), while still allowing platforms that don't to override createMenu() for special-casing system tray menus. Task-number: QTBUG-57365 Change-Id: Id393e802ac0435200fc885a7f4436b744962f27f Reviewed-by: J-P Nurmi --- src/gui/kernel/qplatformsystemtrayicon.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qplatformsystemtrayicon.cpp b/src/gui/kernel/qplatformsystemtrayicon.cpp index 30db966df7..973b998059 100644 --- a/src/gui/kernel/qplatformsystemtrayicon.cpp +++ b/src/gui/kernel/qplatformsystemtrayicon.cpp @@ -40,6 +40,9 @@ #include "qplatformsystemtrayicon.h" +#include +#include + #ifndef QT_NO_SYSTEMTRAYICON QT_BEGIN_NAMESPACE @@ -158,11 +161,10 @@ QPlatformSystemTrayIcon::~QPlatformSystemTrayIcon() */ /*! - This method is called in case there is no QPlatformMenu available when - updating the menu. This allows the abstraction to provide a menu for the - system tray icon even if normally a non-native menu is used. - - The default implementation returns a null pointer. + This method allows platforms to use a different QPlatformMenu for system + tray menus than what would normally be used for e.g. menu bars. The default + implementation falls back to a platform menu created by the platform theme, + which may be null on platforms without native menus. \sa updateMenu() \since 5.3 @@ -170,7 +172,7 @@ QPlatformSystemTrayIcon::~QPlatformSystemTrayIcon() QPlatformMenu *QPlatformSystemTrayIcon::createMenu() const { - return Q_NULLPTR; + return QGuiApplicationPrivate::platformTheme()->createPlatformMenu(); } QT_END_NAMESPACE -- cgit v1.2.3