Fall back to platform theme in QPlatformSystemTrayIcon::createMenu()
Commitbb10824f08046introduced 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. Commit063997f44fthen 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>
parent
7e3e5b2dcf
commit
4a738424aa
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue