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().

Pick-to: 5.15
Change-Id: Ifa29065c447b0d3431e0f14aacb5aafce61051c2
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
bb10
Morten Johan Sørvig 2020-06-03 15:27:07 +02:00
parent c3f74bdc3f
commit e93ec716bf
1 changed files with 3 additions and 1 deletions

View File

@ -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());