QSystemTrayIcon: Allow resetting context menu
Fix logic in QSystemTrayIconPrivate::updateMenu_sys() to allow resetting the tray icon menu. Now we correctly handle `nullptr` menu, and update the underlying QPlatformSystemTrayIcon instance accordingly. Also we bail out from QSystemTrayIcon::setContextMenu() early if the menu is the same. Fixes: QTBUG-119068 Pick-to: 6.5 Change-Id: I704b40dfb1a3046331aef65417655411bf3a41a0 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit c1d389a132d291fb404bef11de3c1b45dbfa2afc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b44828959e
commit
8fcd3b1b1b
@ -162,9 +162,13 @@ void QSystemTrayIcon::setContextMenu(QMenu *menu)
|
|||||||
{
|
{
|
||||||
Q_D(QSystemTrayIcon);
|
Q_D(QSystemTrayIcon);
|
||||||
QMenu *oldMenu = d->menu.data();
|
QMenu *oldMenu = d->menu.data();
|
||||||
|
if (oldMenu == menu)
|
||||||
|
return;
|
||||||
|
|
||||||
d->menu = menu;
|
d->menu = menu;
|
||||||
d->updateMenu_sys();
|
d->updateMenu_sys();
|
||||||
if (oldMenu != menu && d->qpa_sys) {
|
|
||||||
|
if (d->qpa_sys) {
|
||||||
// Show the QMenu-based menu for QPA plugins that do not provide native menus
|
// Show the QMenu-based menu for QPA plugins that do not provide native menus
|
||||||
if (oldMenu && !oldMenu->platformMenu())
|
if (oldMenu && !oldMenu->platformMenu())
|
||||||
QObject::disconnect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, menu, nullptr);
|
QObject::disconnect(d->qpa_sys, &QPlatformSystemTrayIcon::contextMenuRequested, menu, nullptr);
|
||||||
|
@ -59,9 +59,13 @@ void QSystemTrayIconPrivate::updateIcon_sys()
|
|||||||
void QSystemTrayIconPrivate::updateMenu_sys()
|
void QSystemTrayIconPrivate::updateMenu_sys()
|
||||||
{
|
{
|
||||||
#if QT_CONFIG(menu)
|
#if QT_CONFIG(menu)
|
||||||
if (qpa_sys && menu) {
|
if (qpa_sys) {
|
||||||
|
if (menu) {
|
||||||
addPlatformMenu(menu);
|
addPlatformMenu(menu);
|
||||||
qpa_sys->updateMenu(menu->platformMenu());
|
qpa_sys->updateMenu(menu->platformMenu());
|
||||||
|
} else {
|
||||||
|
qpa_sys->updateMenu(nullptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user