From 414c751c7d8c81f7325a3ddee1d120a2056d05cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 20 Apr 2017 14:04:18 +0200 Subject: [PATCH] Fall back to QWindow's screen when resolving DPR instead of using qApp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QGuiApplication::devicePixelRatio() should only be used when we don't know which window we're targeting. For QWindow::devicePixelRatio(), we can go though the associated screen to get a more accurate DPR. Change-Id: Idf511fa5c09562a6daf391cd4d0b8b99471045e7 Reviewed-by: Friedemann Kleint Reviewed-by: Lars Knoll Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qwindow.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index c7afcce874..519d749b8a 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1198,20 +1198,19 @@ Qt::ScreenOrientation QWindow::contentOrientation() const Common values are 1.0 on normal displays and 2.0 on Apple "retina" displays. \note For windows not backed by a platform window, meaning that create() was not - called, the function will fall back to QGuiApplication::devicePixelRatio() which in - turn returns the highest screen device pixel ratio found on the system. + called, the function will fall back to the associated QScreen's device pixel ratio. - \sa QScreen::devicePixelRatio(), QGuiApplication::devicePixelRatio() + \sa QScreen::devicePixelRatio() */ qreal QWindow::devicePixelRatio() const { Q_D(const QWindow); - // If there is no platform window use the app global devicePixelRatio, - // which is the the highest devicePixelRatio found on the system - // screens, and will be correct for single-display systems (a very common case). + // If there is no platform window use the associated screen's devicePixelRatio, + // which typically is the primary screen and will be correct for single-display + // systems (a very common case). if (!d->platformWindow) - return qApp->devicePixelRatio(); + return screen()->devicePixelRatio(); return d->platformWindow->devicePixelRatio() * QHighDpiScaling::factor(this); }