Merge "High-DPI: Set the minimum scale factor to 1"

bb10
Morten Johan Sørvig 2021-02-24 00:06:26 +01:00 committed by Qt CI Bot
commit 2a5262c0dd
2 changed files with 18 additions and 5 deletions

View File

@ -436,11 +436,9 @@ qreal QHighDpiScaling::roundScaleFactor(qreal rawFactor)
break;
}
// Don't round down to to zero; clamp the minimum (rounded) factor to 1.
// This is not a common case but can happen if a display reports a very
// low DPI.
if (scaleFactorRoundingPolicy != Qt::HighDpiScaleFactorRoundingPolicy::PassThrough)
roundedFactor = qMax(roundedFactor, qreal(1));
// Clamp the minimum factor to 1. Qt does not currently render
// correctly with factors less than 1.
roundedFactor = qMax(roundedFactor, qreal(1));
return roundedFactor;
}

View File

@ -49,6 +49,7 @@ private slots:
void initTestCase();
void qhighdpiscaling_data();
void qhighdpiscaling();
void minimumDpr();
void noscreens();
void screenDpiAndDpr_data();
void screenDpiAndDpr();
@ -223,6 +224,20 @@ void tst_QHighDpi::screenDpiAndDpr()
}
}
void tst_QHighDpi::minimumDpr()
{
QList<qreal> dpiValues { 40, 60, 95 };
std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues));
for (QScreen *screen : app->screens()) {
// Qt does not currently support DPR values < 1. Make sure
// the minimum DPR value is 1, also when the screen reports
// a low DPI.
QCOMPARE(screen->devicePixelRatio(), 1);
QWindow window(screen);
QCOMPARE(window.devicePixelRatio(), 1);
}
}
void tst_QHighDpi::noscreens()
{
// Create application object with a no-screens configuration (should not crash)