diff options
Diffstat (limited to 'src/widgets/util/qsystemtrayicon.cpp')
-rw-r--r-- | src/widgets/util/qsystemtrayicon.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index 11214d93eb..19c22eca46 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -61,6 +61,9 @@ #include "qdesktopwidget.h" #include "qbitmap.h" +#include <private/qhighdpiscaling_p.h> +#include <qpa/qplatformscreen.h> + QT_BEGIN_NAMESPACE static QIcon messageIcon2qIcon(QSystemTrayIcon::MessageIcon icon) @@ -196,8 +199,23 @@ QSystemTrayIcon::~QSystemTrayIcon() void QSystemTrayIcon::setContextMenu(QMenu *menu) { Q_D(QSystemTrayIcon); + QMenu *oldMenu = d->menu.data(); d->menu = menu; d->updateMenu_sys(); + if (oldMenu != menu && d->qpa_sys) { + // Show the QMenu-based menu for QPA plugins that do not provide native menus + if (oldMenu && !oldMenu->platformMenu()) + QObject::disconnect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, menu, nullptr); + if (menu && !menu->platformMenu()) { + QObject::connect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, + menu, + [menu](QPoint globalNativePos, const QPlatformScreen *platformScreen) + { + QScreen *screen = platformScreen ? platformScreen->screen() : nullptr; + menu->popup(QHighDpi::fromNativePixels(globalNativePos, screen), nullptr); + }); + } + } } /*! @@ -323,7 +341,9 @@ bool QSystemTrayIcon::event(QEvent *e) \value Unknown Unknown reason \value Context The context menu for the system tray entry was requested - \value DoubleClick The system tray entry was double clicked + \value DoubleClick The system tray entry was double clicked. \note On macOS, a + double click will only be emitted if no context menu is set, since the menu + opens on mouse press \value Trigger The system tray entry was clicked \value MiddleClick The system tray entry was clicked with the middle mouse button @@ -348,7 +368,7 @@ bool QSystemTrayIcon::event(QEvent *e) Currently this signal is not sent on \macos. - \note We follow Microsoft Windows XP/Vista behavior, so the + \note We follow Microsoft Windows behavior, so the signal is also emitted when the user clicks on a tray icon with a balloon message displayed. |