diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 0f4803d92a..d0d2a5a119 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -494,7 +494,8 @@ void QHighDpiScaling::updateHighDpiScaling() qCDebug(lcHighDpi) << "Applying screen factors" << m_screenFactors; int i = -1; const auto screens = QGuiApplication::screens(); - for (const auto &[name, factor] : m_screenFactors) { + for (const auto &[name, rawFactor]: m_screenFactors) { + const qreal factor = roundScaleFactor(rawFactor); ++i; if (name.isNull()) { if (i < screens.size()) diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index fad3df4daa..b062a88c1f 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -313,9 +313,10 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() QFETCH(QByteArray, environment); QFETCH(QList, expectedDprValues); + qputenv("QT_SCREEN_SCALE_FACTORS", environment); + // Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-platform-screen-DPI DPR. { - qputenv("QT_SCREEN_SCALE_FACTORS", environment); std::unique_ptr app(createStandardOffscreenApp(platformScreenDpi)); int i = 0; for (QScreen *screen : app->screens()) { @@ -327,6 +328,18 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() QCOMPARE(window.devicePixelRatio(), expextedDpr); } } + + // Verify that setHighDpiScaleFactorRoundingPolicy applies to QT_SCREEN_SCALE_FACTORS as well + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + { + std::unique_ptr app(createStandardOffscreenApp(platformScreenDpi)); + int i = 0; + for (QScreen *screen : app->screens()) { + qreal expectedRounderDpr = qRound(expectedDprValues[i++]); + qreal windowDpr = QWindow(screen).devicePixelRatio(); + QCOMPARE(windowDpr, expectedRounderDpr); + } + } } void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI()