diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2020-06-03 15:27:07 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2020-08-19 15:11:27 +0000 |
commit | e1254f0700bcdc51781468d93ae94a158d18a8df (patch) | |
tree | cbc892616cef1ee5ffee340a80bd66326b5a149d /src/gui | |
parent | 0f98cab80ae1cd7350d01a911cba433df44f1dee (diff) |
High-DPI: Use correct DPI for QT_USE_PHYSICAL_DPI
Setting the QT_USE_PHYSICAL_DPI environment variable
will make Qt use physical DPI when determining the
screen scale factor, instead of logical DPI.
However, the code was using QScreen::physicalDotsPerInch(),
Whose return value is itself scaled by the device
pixel ratio. (See QTBUG-62649 for further discussion).
Use QPlatformScreen API instead and calculate the DPI
based on geometry() and physicalSize().
Change-Id: Ifa29065c447b0d3431e0f14aacb5aafce61051c2
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
(cherry picked from commit e93ec716bf839686f7ffffc33958d90a58725e9b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qhighdpiscaling.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 671c2d93ef..b7d97ca172 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -294,7 +294,9 @@ qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen) qreal factor; QDpi platformBaseDpi = screen->logicalBaseDpi(); if (usePhysicalDpi) { - qreal platformPhysicalDpi = screen->screen()->physicalDotsPerInch(); + QSize sz = screen->geometry().size(); + QSizeF psz = screen->physicalSize(); + qreal platformPhysicalDpi = ((sz.height() / psz.height()) + (sz.width() / psz.width())) * qreal(25.4 * 0.5); factor = qreal(platformPhysicalDpi) / qreal(platformBaseDpi.first); } else { const QDpi platformLogicalDpi = QPlatformScreen::overrideDpi(screen->logicalDpi()); |