Windows: regenerate systray icon when screen resolution changes
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 Pick-to: 6.4 6.2 Change-Id: If3dd042416b7f61bbb3b43f7d563e52b406136a2 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
be36b6356a
commit
9bc36308c7
@ -164,6 +164,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);
|
||||
@ -402,8 +403,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user