diff options
author | Yuhang Zhao <2546789017@qq.com> | 2022-11-23 11:23:49 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-12-14 02:33:26 +0800 |
commit | 67284763e7ce0d12650b652e92dfd022a8affb1d (patch) | |
tree | f6c27d0a7c356ea4ca61591faf26665b7b482dee /src/plugins/platforms/windows/qwindowswindow.cpp | |
parent | faffaa729282b435fb330e1c92523fc0df3fc051 (diff) |
HiDPI: fix wrong window size after DPI change
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 <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowswindow.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
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<SIZE *>(lParam); size->cx = windowSize.width(); size->cy = windowSize.height(); |