diff options
author | Victor-Andrei Variu <victor.variu@corebuild.eu> | 2017-08-14 15:47:26 +0300 |
---|---|---|
committer | Morten Johan Sørvig <morten.sorvig@qt.io> | 2017-11-17 13:53:39 +0000 |
commit | b72b5cd76004e54dc00c0f1133f4d59192ef154a (patch) | |
tree | 0bc1a31e1ff7517623c9fde65f0ac507baf7ad1a /src/gui/kernel/qhighdpiscaling.cpp | |
parent | 12aa50175268064b3da36473ec0196cbdb1bdf7f (diff) |
Adjust screen scale factor for certain screen configurations
Pixel density reported by the screen is sometimes not precise enough,
so recalculate it: divide px (physical pixels) by dp (device-independent pixels)
for both width and height, and then use the average if it is different
from the one initially reported by the screen
Task-number: QTBUG-62191
Change-Id: Ia2f485c7ce8849db6e7c1d2ac08f5e008aea2ff8
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/gui/kernel/qhighdpiscaling.cpp')
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 085652879c..078f185d08 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -376,8 +376,22 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) { qreal factor = qreal(1.0); if (screen) { - if (m_usePixelDensity) - factor *= screen->pixelDensity(); + if (m_usePixelDensity) { + qreal pixelDensity = screen->pixelDensity(); + + // Pixel density reported by the screen is sometimes not precise enough, + // so recalculate it: divide px (physical pixels) by dp (device-independent pixels) + // for both width and height, and then use the average if it is different from + // the one initially reported by the screen + QRect screenGeometry = screen->geometry(); + qreal wFactor = qreal(screenGeometry.width()) / qRound(screenGeometry.width() / pixelDensity); + qreal hFactor = qreal(screenGeometry.height()) / qRound(screenGeometry.height() / pixelDensity); + qreal averageDensity = (wFactor + hFactor) / 2; + if (!qFuzzyCompare(pixelDensity, averageDensity)) + pixelDensity = averageDensity; + + factor *= pixelDensity; + } if (m_screenFactorSet) { QVariant screenFactor = screen->screen()->property(scaleFactorProperty); if (screenFactor.isValid()) |