From 67284763e7ce0d12650b652e92dfd022a8affb1d Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Wed, 23 Nov 2022 11:23:49 +0800 Subject: [PATCH] HiDPI: fix wrong window size after DPI change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current code doesn't take the custom margins into account, it will cause windows with custom margins have wrong size after DPI change. Amends commit 2cfca7fd1911cc82a22763152c04c65bc05bc19a Pick-to: 6.5 6.4 Change-Id: I80b01c030a63d02cf66f105785df7c3f590481b5 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/windows/qwindowswindow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index b2e41dca24..f7ba002673 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1966,7 +1966,13 @@ void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT * const qreal scale = QHighDpiScaling::roundScaleFactor(qreal(dpi) / QWindowsScreen::baseDpi) / QHighDpiScaling::roundScaleFactor(qreal(savedDpi()) / QWindowsScreen::baseDpi); const QMargins margins = QWindowsGeometryHint::frame(window(), style(), exStyle(), dpi); - const QSize windowSize = (geometry().size() * scale).grownBy(margins); + // We need to update the custom margins to match the current DPI, because + // we don't want our users manually hook into this message just to set a + // new margin, but here we can't call setCustomMargins() directly, that + // function will change the window geometry which conflicts with what we + // are currently doing. + m_data.customMargins *= scale; + const QSize windowSize = (geometry().size() * scale).grownBy(margins + customMargins()); SIZE *size = reinterpret_cast(lParam); size->cx = windowSize.width(); size->cy = windowSize.height();