diff options
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 18 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 2 |
2 files changed, 9 insertions, 11 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 70bc407587..17f87ef87c 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -12770,8 +12770,6 @@ void QWidget::activateWindow() */ int QWidget::metric(PaintDeviceMetric m) const { - Q_D(const QWidget); - QWindow *topLevelWindow = 0; QScreen *screen = 0; if (QWidget *topLevel = window()) { @@ -12799,16 +12797,16 @@ int QWidget::metric(PaintDeviceMetric m) const } else if (m == PdmDepth) { return screen->depth(); } else if (m == PdmDpiX) { - if (d->extra && d->extra->customDpiX) - return d->extra->customDpiX; - else if (d->parent) - return static_cast<QWidget *>(d->parent)->metric(m); + for (const QWidget *p = this; p; p = p->parentWidget()) { + if (p->d_func()->extra && p->d_func()->extra->customDpiX) + return p->d_func()->extra->customDpiX; + } return qRound(screen->logicalDotsPerInchX()); } else if (m == PdmDpiY) { - if (d->extra && d->extra->customDpiY) - return d->extra->customDpiY; - else if (d->parent) - return static_cast<QWidget *>(d->parent)->metric(m); + for (const QWidget *p = this; p; p = p->parentWidget()) { + if (p->d_func()->extra && p->d_func()->extra->customDpiY) + return p->d_func()->extra->customDpiY; + } return qRound(screen->logicalDotsPerInchY()); } else if (m == PdmPhysicalDpiX) { return qRound(screen->physicalDotsPerInchX()); diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 7afa7ca42b..5715505fd6 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -8181,7 +8181,7 @@ void tst_QWidget::customDpi() custom->logicalDpiX(); QCOMPARE(custom->metricCallCount, 1); child->logicalDpiX(); - QCOMPARE(custom->metricCallCount, 2); + QCOMPARE(custom->metricCallCount, 1); } void tst_QWidget::customDpiProperty() |