summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorMorten Sørvig <morten.sorvig@qt.io>2023-04-17 11:39:15 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2023-04-18 12:42:45 +0000
commite3c9dce0b6e5aa1844f51cf2f3bdc550a5b884ce (patch)
treedc7058ebfc33afc793567bc3ba09384963fce234 /src/widgets
parent020f03c47e79b1d409d8edb509abdbf45cffe71d (diff)
Use QHighDpiScaling when determining scale factor
The makes sure that the scale factor used by the style is identical to the scale factor used by Qt Gui, by for instance taking scale factor rounding into account. Task-id: QTBUG-109715 Change-Id: Ia0354a7ce0f51eb9fd5f2591ee6c4057291943f3 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/styles/qwindowsstyle.cpp11
1 files changed, 4 insertions, 7 deletions
diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp
index e48e17ed3b..f79136757a 100644
--- a/src/widgets/styles/qwindowsstyle.cpp
+++ b/src/widgets/styles/qwindowsstyle.cpp
@@ -358,18 +358,15 @@ static QScreen *screenOf(const QWidget *w)
// and account for secondary screens with differing logical DPI.
qreal QWindowsStylePrivate::nativeMetricScaleFactor(const QWidget *widget)
{
- const QPlatformScreen *screen = screenOf(widget)->handle();
- const qreal scale = screen ? (screen->logicalDpi().first / screen->logicalBaseDpi().first)
- : QWindowsStylePrivate::appDevicePixelRatio();
+ qreal scale = QHighDpiScaling::factor(screenOf(widget));
qreal result = qreal(1) / scale;
if (QGuiApplicationPrivate::screen_list.size() > 1) {
const QScreen *primaryScreen = QGuiApplication::primaryScreen();
const QScreen *screen = screenOf(widget);
if (screen != primaryScreen) {
- const qreal primaryLogicalDpi = primaryScreen->handle()->logicalDpi().first;
- const qreal logicalDpi = screen->handle()->logicalDpi().first;
- if (!qFuzzyCompare(primaryLogicalDpi, logicalDpi))
- result *= logicalDpi / primaryLogicalDpi;
+ qreal primaryScale = QHighDpiScaling::factor(primaryScreen);
+ if (!qFuzzyCompare(scale, primaryScale))
+ result *= scale / primaryScale;
}
}
return result;