summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-02-15 14:34:35 +0100
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-03-28 09:14:09 +0000
commit9a39b3c796e603c8a82f4f9968467b5aeb43be30 (patch)
treed80946d1da622ed759534c3280caef305e4a5fcd /tests/auto/gui/kernel
parent2d76f991d01763f5432fc6ba7ae073393f224557 (diff)
Apply ScaleFactorRoundingPolicy to QT_SCREEN_SCALE_FACTORS
QT_SCREEN_SCALE_FACTORS is in many cases set on behalf of the user, instead of by the user, so we should apply the standard app scale factor policies to it, instead of interpreting it as a user override. Specifically, make it subject to the rounding policy set by QGuiApplication::setHighDpiScaleFactorRoundingPolicy(). This means that applications which support integer scale factors only will see integers only, also when QT_SCREEN_SCALE_FACTORS specifies a fractional factor. Users who want to override can set QT_SCALE_FACTOR_ROUNDING_POLICY=PassThrough to restore the default Qt rounding behavior. [ChangeLog][QtGui] The high-DPI scale factor rounding policy (settable with QGuiApplication::setHighDpiScaleFactorRoundingPolicy() or QT_SCALE_FACTOR_ROUNDING_POLICY) now applies to scale factors set with QT_SCREEN_SCALE_FACTORS. Fixes: QTBUG-95930 Fixes: QTBUG-99546 Change-Id: I936e96671fe2a0a43c3e8129f0768875cb011103 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp15
1 files changed, 14 insertions, 1 deletions
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<qreal>, 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<QGuiApplication> 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<QGuiApplication> 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()