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 2cfca7fd19

Pick-to: 6.5 6.4
Change-Id: I80b01c030a63d02cf66f105785df7c3f590481b5
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Yuhang Zhao 2022-11-23 11:23:49 +08:00
parent faffaa7292
commit 67284763e7

View File

@ -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();