Windows: Don't rely on top level QWindow to scale children on DPI change
The native size of a QWindow on Windows is the logical size of the window times the window's device pixel ratio. We manage this relationship for top level windows via the WM_GETDPISCALEDSIZE message, and during WM_DPICHANGED we then applied the same scale to child windows. This is problematic in the case where a child window does not have a QWindow parent, so instead of scaling all children when the parent gets a WM_DPICHANGED message, we scale each individual child in the child's WM_DPICHANGED_AFTERPARENT message. Task-number: QTBUG-103383 Change-Id: Ia0845aa19a3bb97b7bc9e7d9554ac02b95ca65a5 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 97665c9615ff399e9a074b94926ab06e0c9619e5) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
379198828c
commit
90b19e39ad
@ -1966,7 +1966,6 @@ void QWindowsWindow::handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *
|
|||||||
void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
const UINT dpi = HIWORD(wParam);
|
const UINT dpi = HIWORD(wParam);
|
||||||
const qreal scale = qreal(dpi) / qreal(savedDpi());
|
|
||||||
setSavedDpi(dpi);
|
setSavedDpi(dpi);
|
||||||
|
|
||||||
// Send screen change first, so that the new screen is set during any following resize
|
// Send screen change first, so that the new screen is set during any following resize
|
||||||
@ -1995,24 +1994,21 @@ void QWindowsWindow::handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
|
|||||||
prcNewWindow->right - prcNewWindow->left,
|
prcNewWindow->right - prcNewWindow->left,
|
||||||
prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale child QPlatformWindow size. Windows sends WM_DPICHANGE to top-level windows only.
|
|
||||||
for (QWindow *childWindow : window()->findChildren<QWindow *>()) {
|
|
||||||
QWindowsWindow *platformChildWindow = static_cast<QWindowsWindow *>(childWindow->handle());
|
|
||||||
if (!platformChildWindow)
|
|
||||||
continue;
|
|
||||||
QRect currentGeometry = platformChildWindow->geometry();
|
|
||||||
QRect scaledGeometry = QRect(currentGeometry.topLeft() * scale, currentGeometry.size() * scale);
|
|
||||||
platformChildWindow->setGeometry(scaledGeometry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QWindowsWindow::handleDpiChangedAfterParent(HWND hwnd)
|
void QWindowsWindow::handleDpiChangedAfterParent(HWND hwnd)
|
||||||
{
|
{
|
||||||
// FIXME: refactor, do we really need this?
|
const UINT dpi = GetDpiForWindow(hwnd);
|
||||||
setSavedDpi(GetDpiForWindow(hwnd));
|
const qreal scale = qreal(dpi) / qreal(savedDpi());
|
||||||
|
setSavedDpi(dpi);
|
||||||
|
|
||||||
checkForScreenChanged(QWindowsWindow::FromDpiChange);
|
checkForScreenChanged(QWindowsWindow::FromDpiChange);
|
||||||
|
|
||||||
|
// Child windows do not get WM_GETDPISCALEDSIZE messages to inform
|
||||||
|
// Windows about the new size, so we need to manually scale them.
|
||||||
|
QRect currentGeometry = geometry();
|
||||||
|
QRect scaledGeometry = QRect(currentGeometry.topLeft() * scale, currentGeometry.size() * scale);
|
||||||
|
setGeometry(scaledGeometry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QRect normalFrameGeometry(HWND hwnd)
|
static QRect normalFrameGeometry(HWND hwnd)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user