summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2017-02-22 12:26:39 +0100
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2017-03-02 16:43:38 +0000
commit1d9270ee42c257e6df104053177653cffa76336e (patch)
tree5b1c81399dbfed16068dd22d2f757ccd2583eb66 /src/widgets
parent8cd99d24a8639ad8afef1330a518b37779db62cc (diff)
Fix DPI of QWidget with parent on a different screen
If a floating QWidget has a parent on a different screen, its DPI was still inherited from the parent instead of taken from the screen. The only reason we did was in case there is a customDpi set. (customDpi is a private thing that is only used in designer to change the appearance of the previewed widget) So instead of recursing into QWidget::metric for each ancestor, just use a for loop to find if one parent has a customDpi. If no customDpi is found, then return the DPI of the right screen. Task-number: QTBUG-58959 Task-number: QTBUG-48242 Change-Id: Ie6e9e48cdd10234994c0919ba3aea9b0cdb52494 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qwidget.cpp18
1 files changed, 8 insertions, 10 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());