From e93ec716bf839686f7ffffc33958d90a58725e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 3 Jun 2020 15:27:07 +0200 Subject: [PATCH] High-DPI: Use correct DPI for QT_USE_PHYSICAL_DPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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(). Pick-to: 5.15 Change-Id: Ifa29065c447b0d3431e0f14aacb5aafce61051c2 Reviewed-by: Morten Johan Sørvig --- src/gui/kernel/qhighdpiscaling.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 7107e37e40..726b7bc4b2 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());