From d603ee689f0e3fdcfa3230b3d75cdce6c5af05c1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 4 Apr 2019 13:53:19 +0200 Subject: Widget style: Use per-screen DPI in QStyleHelper::dpiScaled() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass the style option to dpiScaled() in order to get the correct screen DPI. The style option contains the font, which again contains the current DPI value. Add QFontMetrics::fontDpi() accessors to get the DPI from the QFont. This DPI will/should be updated on screen change. Replace hardcoded Q_OS_MAC DPI with hardcoded base DPI. This makes per-screen DPI testable on macOS, too. Task-number: QTBUG-45055 Change-Id: I75f8b37d45eb50c3334b46b8469a546d29712f1b Reviewed-by: Morten Johan Sørvig --- src/widgets/styles/qwindowsstyle.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/widgets/styles/qwindowsstyle.cpp') diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index c13f6e637d..72c803cb99 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -423,7 +423,7 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW ret = QWindowsStylePrivate::fixedPixelMetric(pm); if (ret != QWindowsStylePrivate::InvalidMetric) - return int(QStyleHelper::dpiScaled(ret)); + return int(QStyleHelper::dpiScaled(ret, opt)); ret = 0; @@ -469,7 +469,7 @@ int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QW break; case PM_SplitterWidth: - ret = qMax(int(QStyleHelper::dpiScaled(4)), QApplication::globalStrut().width()); + ret = qMax(int(QStyleHelper::dpiScaled(4, opt)), QApplication::globalStrut().width()); break; default: @@ -793,8 +793,9 @@ void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPen oldPen = p->pen(); p->setPen(QPen(opt->palette.shadow().color(), 0)); QRectF rect = opt->rect; - const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5); - const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5); + const qreal dpi = QStyleHelper::dpi(opt); + const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi); + const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5, dpi); rect.adjust(topLevelAdjustment, topLevelAdjustment, bottomRightAdjustment, bottomRightAdjustment); p->drawRect(rect); @@ -2303,8 +2304,9 @@ QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt, int defwidth = 0; if (btn->features & QStyleOptionButton::AutoDefaultButton) defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget); - int minwidth = int(QStyleHelper::dpiScaled(75.)); - int minheight = int(QStyleHelper::dpiScaled(23.)); + const qreal dpi = QStyleHelper::dpi(opt); + int minwidth = int(QStyleHelper::dpiScaled(75, dpi)); + int minheight = int(QStyleHelper::dpiScaled(23, dpi)); #ifndef QT_QWS_SMALL_PUSHBUTTON if (w < minwidth + defwidth && !btn->text.isEmpty()) -- cgit v1.2.3