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 063997f44f 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 <jpnurmi@qt.io>
bb10
Tor Arne Vestbø 2017-01-05 15:01:02 +01:00 committed by Jani Heikkinen
parent 7e3e5b2dcf
commit 4a738424aa
1 changed files with 8 additions and 6 deletions

View File

@ -40,6 +40,9 @@
#include "qplatformsystemtrayicon.h"
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformtheme.h>
#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