From 49d6a259cdcdcd693a6e9878133a5d84a4bbcb6a Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Fri, 2 Dec 2022 18:24:23 +0100 Subject: [PATCH] Windows: regenerate systray icon when screen resolution changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the screen resolution or scale factor changes, then we have to recreate the system tray icon so that it doesn't get blurry. Such changes generate a WM_TASKBARCREATED message, which we already handle through a self-registered message ID to re-add the icon when the task bar/explorer crashed. So call updateIcon there to recreate the HICON before adding it again. For this to work, we have to actually store the QIcon in the already present (but so far unused) m_icon member, and reset that member before calling updateIcon, which would otherwise be a no-op. Fixes: QTBUG-108641 Change-Id: If3dd042416b7f61bbb3b43f7d563e52b406136a2 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 9bc36308c77e10c6a890c3dd6a72dd2f23a72288) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/windows/qwindowssystemtrayicon.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp index cf150b5772a..0b04019d890 100644 --- a/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp +++ b/src/plugins/platforms/windows/qwindowssystemtrayicon.cpp @@ -171,6 +171,7 @@ void QWindowsSystemTrayIcon::updateIcon(const QIcon &icon) qCDebug(lcQpaTrayIcon) << __FUNCTION__ << '(' << icon << ')' << this; if (icon.cacheKey() == m_icon.cacheKey()) return; + m_icon = icon; const HICON hIconToDestroy = createIcon(icon); if (ensureInstalled()) sendTrayMessage(NIM_MODIFY); @@ -409,8 +410,15 @@ bool QWindowsSystemTrayIcon::winEvent(const MSG &message, long *result) QWindowsPopupMenu::notifyTriggered(LOWORD(message.wParam)); break; default: - if (message.message == MYWM_TASKBARCREATED) // self-registered message id (tray crashed) + if (message.message == MYWM_TASKBARCREATED) { + // self-registered message id to handle that + // - screen resolution/DPR changed + const QIcon oldIcon = m_icon; + m_icon = QIcon(); // updateIcon is a no-op if the icon doesn't change + updateIcon(oldIcon); + // - or tray crashed sendTrayMessage(NIM_ADD); + } break; } return false;