From ad10fd2a6f78d48866e59f843acb0248120074ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 4 Mar 2021 15:30:48 +0100 Subject: [PATCH] Round physical dpi when calculating scale factor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (For the QT_USE_PHYSICAL_DPI use case) The physical DPI is nominally computed from the physical screen size, however when QT_USE_PHYSICAL_DPI is set that size has typically been overridden with a fake size by the user, such that the resulting DPI calculation will yield some specific integer DPI. Round this DPI value in order to arrive at a nice scale factor, e.g. 144/96 = 1.5 instead of 144.01/96 = 1.5001 Change-Id: I665394e98a818b3a8f46408f3193cac4411f458d Reviewed-by: Tor Arne Vestbø --- src/gui/kernel/qhighdpiscaling.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 3a70e5acf7..f93ec5fe76 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -293,7 +293,7 @@ qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen) 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); + factor = qRound(platformPhysicalDpi) / qreal(platformBaseDpi.first); } else { const QDpi platformLogicalDpi = QPlatformScreen::overrideDpi(screen->logicalDpi()); factor = qreal(platformLogicalDpi.first) / qreal(platformBaseDpi.first);