summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2020-05-25 15:11:34 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2020-10-20 07:26:31 +0200
commite8fabb29462e6ee268bde5267e3d7bca23addbb2 (patch)
treea65673149497e1a66454296109ac6b9aed151b4c /src/gui/kernel
parent95bce5b185ddc736405a952b9132e5c8f51275aa (diff)
high-dpi: Set screen on QWindow::setGeometry()
Keep (requested) geometry and screen in sync, which is required for correct high-dpi scaling. The platform plugin can still override with new geometry (and screen), as usual. This has previously been fixed/worked around for QDialog, see QTBUG-52735. That fix can now be removed in favor of this change in QWindow. Change-Id: Ieadb1bfee5fb966c5c2052e9daa5ba124a87f3cd Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qwindow.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 867e658be5..131f55908b 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -529,6 +529,13 @@ void QWindowPrivate::create(bool recursive, WId nativeHandle)
if (q->parent())
q->parent()->create();
+ // QPlatformWindow will poll geometry() during construction below. Set the
+ // screen here so that high-dpi scaling will use the correct scale factor.
+ if (q->isTopLevel()) {
+ if (QScreen *screen = screenForGeometry(geometry))
+ setTopLevelScreen(screen, false);
+ }
+
QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
platformWindow = nativeHandle ? platformIntegration->createForeignWindow(q, nativeHandle)
: platformIntegration->createPlatformWindow(q);
@@ -1726,9 +1733,12 @@ void QWindow::setGeometry(const QRect &rect)
d->positionPolicy = QWindowPrivate::WindowFrameExclusive;
if (d->platformWindow) {
- QRect nativeRect;
QScreen *newScreen = d->screenForGeometry(rect);
if (newScreen && isTopLevel())
+ d->setTopLevelScreen(newScreen, true);
+
+ QRect nativeRect;
+ if (newScreen && isTopLevel())
nativeRect = QHighDpi::toNativePixels(rect, newScreen);
else
nativeRect = QHighDpi::toNativeLocalPosition(rect, newScreen);