From 04bc5fa4bebc9900a9f9a9fda911f6990a7f28a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Keller?= Date: Mon, 15 May 2023 19:55:50 +0200 Subject: [PATCH] Windows QPA: Fix dpi change when changing screens with keyboard If moving a window from a screen to another using keyboard shortcuts, the screen change detection happens after the handleDpiChange() call which essentially makes Qt think the window stayed on the old monitor. Instead of checking against currentScreen DPI, check against savedDpi which should not have this problem. Task-number: QTBUG-106483 Change-Id: Ic30dc1b16bbaf9306a086c8d3042f5341d3848c1 Reviewed-by: Oliver Wolff (cherry picked from commit 1d3b06a1abb715efc38f88ecd369f96d6e8cadd6) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowswindow.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index aaa3933acd8..d1aeab87db9 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2238,10 +2238,10 @@ void QWindowsWindow::checkForScreenChanged(ScreenChangeMode mode) return; // For screens with different DPI: postpone until WM_DPICHANGE // Check on currentScreen as it can be 0 when resuming a session (QTBUG-80436). - if (mode == FromGeometryChange && currentScreen != nullptr - && !equalDpi(currentScreen->logicalDpi(), newScreen->logicalDpi())) { + const bool changingDpi = !equalDpi(QDpi(savedDpi(), savedDpi()), newScreen->logicalDpi()); + if (mode == FromGeometryChange && currentScreen != nullptr && changingDpi) return; - } + qCDebug(lcQpaWindow).noquote().nospace() << __FUNCTION__ << ' ' << window() << " \"" << (currentScreen ? currentScreen->name() : QString()) << "\"->\"" << newScreen->name() << '"';