Fall back to QWindow's screen when resolving DPR instead of using qApp

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 <Friedemann.Kleint@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Tor Arne Vestbø 2017-04-20 14:04:18 +02:00
parent b4c8455eeb
commit 414c751c7d

View File

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