From 316946089d565a640ecfa62d093a1cca3e65c448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Keller?= Date: Tue, 9 Jan 2024 13:21:24 +0100 Subject: [PATCH] Windows QPA: Prevent restoreGeometry from showing hidden windows When we use GetWindowPlacement, the showCmd parameter will NOT be SW_HIDE, even if the window is hidden. To prevent showing a hidden window with SetWindowPlacement, change showCmd if the window is currently hidden. Amends 21e411687428d05655b8db2634466384fa35cc03 Fixes: QTBUG-120415 Change-Id: Ib7de369a6d1a530fdeb5ff930097ae06e25761f3 Reviewed-by: Oliver Wolff Reviewed-by: Zhao Yuhang (cherry picked from commit 8a5fed6da41bcc29506d5b4e166a6e87e8fe9eb7) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/platforms/windows/qwindowswindow.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index c54da57ffe8..4517433135b 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -2480,6 +2480,11 @@ void QWindowsWindow::handleWindowStateChange(Qt::WindowStates state) GetWindowPlacement(m_data.hwnd, &windowPlacement); const RECT geometry = RECTfromQRect(m_data.restoreGeometry); windowPlacement.rcNormalPosition = geometry; + // Even if the window is hidden, windowPlacement's showCmd is not SW_HIDE, so change it + // manually to avoid unhiding a hidden window with the subsequent call to + // SetWindowPlacement(). + if (!isVisible()) + windowPlacement.showCmd = SW_HIDE; SetWindowPlacement(m_data.hwnd, &windowPlacement); } // QTBUG-17548: We send expose events when receiving WM_Paint, but for