summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2014-04-01 14:54:24 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-05 08:16:23 +0200
commit687fbc11525fddda73ba4925d916be555df22ca9 (patch)
tree305b9228f2e64f54a62b7968b604551daa5f688d /src
parent2884d7c9aafda5ad2d84f1c7a1b4ea2625182885 (diff)
Improve QWidget::metric for PdmDevicePixelRatio.
Use QWindow::devicePixelRatio() which is the most accurate devicePixelRatio accessor since it can ask the platform native window directly Fall back to qApp->devicePixelRatio() if the window pointer is not valid. Task-number: QTBUG-37606 Task-number: QTBUG-38078 Change-Id: Ief1468a0c6ced07439f55329ab056883016241cc Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qwidget_qpa.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/widgets/kernel/qwidget_qpa.cpp b/src/widgets/kernel/qwidget_qpa.cpp
index 85ae55b8ac..c22320e8d2 100644
--- a/src/widgets/kernel/qwidget_qpa.cpp
+++ b/src/widgets/kernel/qwidget_qpa.cpp
@@ -834,13 +834,16 @@ int QWidget::metric(PaintDeviceMetric m) const
{
Q_D(const QWidget);
+ QWindow *topLevelWindow = 0;
QScreen *screen = 0;
if (QWidget *topLevel = window())
- if (QWindow *topLevelWindow = topLevel->windowHandle()) {
- QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
- if (platformScreen)
- screen = platformScreen->screen();
- }
+ topLevelWindow = topLevel->windowHandle();
+
+ if (topLevelWindow) {
+ QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(topLevelWindow);
+ if (platformScreen)
+ screen = platformScreen->screen();
+ }
if (!screen && QGuiApplication::primaryScreen())
screen = QGuiApplication::primaryScreen();
@@ -877,7 +880,7 @@ int QWidget::metric(PaintDeviceMetric m) const
} else if (m == PdmPhysicalDpiY) {
return qRound(screen->physicalDotsPerInchY());
} else if (m == PdmDevicePixelRatio) {
- return screen->devicePixelRatio();
+ return topLevelWindow ? topLevelWindow->devicePixelRatio() : qApp->devicePixelRatio();
} else {
val = QPaintDevice::metric(m);// XXX
}