From 86121b582147e0515d856ae4dfa4816675af2905 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 29 Nov 2016 15:08:09 +0100 Subject: [PATCH] WIP: Widget style: Use per-screen DPI in QStyleHelper::dpiScaled() Pass QStyleOption and widget to dpiScaled() in order to find the correct screen DPI. Add functions to retrieve the associated screen for widgets and QQuickStyleItems. Task-number: QTBUG-45055 Change-Id: I75f8b37d45eb50c3334b46b8469a546d29712f1b --- src/widgets/styles/qcommonstyle.cpp | 88 +++++++++++++++---------------- src/widgets/styles/qfusionstyle.cpp | 10 ++-- src/widgets/styles/qstylehelper.cpp | 61 +++++++++++++++++++-- src/widgets/styles/qstylehelper_p.h | 3 +- src/widgets/styles/qwindowsstyle.cpp | 8 +-- src/widgets/styles/qwindowsvistastyle.cpp | 4 +- src/widgets/styles/qwindowsxpstyle.cpp | 9 ++-- 7 files changed, 119 insertions(+), 64 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 690c811..fb863e9 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4369,13 +4369,13 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid ret = 0; break; case PM_DialogButtonsSeparator: - ret = int(QStyleHelper::dpiScaled(5.)); + ret = int(QStyleHelper::dpiScaled(5, opt, widget)); break; case PM_DialogButtonsButtonWidth: - ret = int(QStyleHelper::dpiScaled(70.)); + ret = int(QStyleHelper::dpiScaled(70, opt, widget)); break; case PM_DialogButtonsButtonHeight: - ret = int(QStyleHelper::dpiScaled(30.)); + ret = int(QStyleHelper::dpiScaled(30, opt, widget)); break; case PM_TitleBarHeight: { if (const QStyleOptionTitleBar *tb = qstyleoption_cast(opt)) { @@ -4383,29 +4383,29 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid ret = qMax(widget ? widget->fontMetrics().height() : opt->fontMetrics.height(), 16); #ifndef QT_NO_DOCKWIDGET } else if (qobject_cast(widget)) { - ret = qMax(widget->fontMetrics().height(), int(QStyleHelper::dpiScaled(13))); + ret = qMax(widget->fontMetrics().height(), int(QStyleHelper::dpiScaled(13, opt, widget))); #endif } else { ret = qMax(widget ? widget->fontMetrics().height() : opt->fontMetrics.height(), 18); } } else { - ret = int(QStyleHelper::dpiScaled(18.)); + ret = int(QStyleHelper::dpiScaled(18., opt, widget)); } break; } case PM_TitleBarButtonSize: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16., opt, widget)); break; case PM_TitleBarButtonIconSize: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16., opt, widget)); break; case PM_ScrollBarSliderMin: - ret = int(QStyleHelper::dpiScaled(9.)); + ret = int(QStyleHelper::dpiScaled(9., opt, widget)); break; case PM_ButtonMargin: - ret = int(QStyleHelper::dpiScaled(6.)); + ret = int(QStyleHelper::dpiScaled(6., opt, widget)); break; case PM_DockWidgetTitleBarButtonMargin: @@ -4417,7 +4417,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_MenuButtonIndicator: - ret = int(QStyleHelper::dpiScaled(12.)); + ret = int(QStyleHelper::dpiScaled(12, opt, widget)); break; case PM_ButtonShiftHorizontal: @@ -4436,11 +4436,11 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_MdiSubWindowFrameWidth: - ret = int(QStyleHelper::dpiScaled(4.)); + ret = int(QStyleHelper::dpiScaled(4, opt, widget)); break; case PM_MdiSubWindowMinimizedWidth: - ret = int(QStyleHelper::dpiScaled(196.)); + ret = int(QStyleHelper::dpiScaled(196, opt, widget)); break; #ifndef QT_NO_SCROLLBAR @@ -4451,7 +4451,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid : QApplication::globalStrut().width(); ret = qMax(16, s); } else { - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16, opt, widget)); } break; #endif @@ -4461,7 +4461,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid #ifndef QT_NO_SLIDER case PM_SliderThickness: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16, opt, widget)); break; case PM_SliderTickmarkOffset: @@ -4495,11 +4495,11 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid #endif // QT_NO_SLIDER #ifndef QT_NO_DOCKWIDGET case PM_DockWidgetSeparatorExtent: - ret = int(QStyleHelper::dpiScaled(6.)); + ret = int(QStyleHelper::dpiScaled(6, opt, widget)); break; case PM_DockWidgetHandleExtent: - ret = int(QStyleHelper::dpiScaled(8.)); + ret = int(QStyleHelper::dpiScaled(8, opt, widget)); break; case PM_DockWidgetTitleMargin: ret = 0; @@ -4528,19 +4528,19 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_ToolBarItemSpacing: - ret = int(QStyleHelper::dpiScaled(4.)); + ret = int(QStyleHelper::dpiScaled(4, opt, widget)); break; case PM_ToolBarHandleExtent: - ret = int(QStyleHelper::dpiScaled(8.)); + ret = int(QStyleHelper::dpiScaled(8, opt, widget)); break; case PM_ToolBarSeparatorExtent: - ret = int(QStyleHelper::dpiScaled(6.)); + ret = int(QStyleHelper::dpiScaled(6, opt, widget)); break; case PM_ToolBarExtensionExtent: - ret = int(QStyleHelper::dpiScaled(12.)); + ret = int(QStyleHelper::dpiScaled(12, opt, widget)); break; #endif // QT_NO_TOOLBAR @@ -4550,7 +4550,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_TabBarTabHSpace: - ret = int(QStyleHelper::dpiScaled(24.)); + ret = int(QStyleHelper::dpiScaled(24, opt, widget)); break; case PM_TabBarTabShiftHorizontal: @@ -4579,27 +4579,27 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_IndicatorWidth: - ret = int(QStyleHelper::dpiScaled(13.)); + ret = int(QStyleHelper::dpiScaled(13, opt, widget)); break; case PM_IndicatorHeight: - ret = int(QStyleHelper::dpiScaled(13.)); + ret = int(QStyleHelper::dpiScaled(13, opt, widget)); break; case PM_ExclusiveIndicatorWidth: - ret = int(QStyleHelper::dpiScaled(12.)); + ret = int(QStyleHelper::dpiScaled(12, opt, widget)); break; case PM_ExclusiveIndicatorHeight: - ret = int(QStyleHelper::dpiScaled(12.)); + ret = int(QStyleHelper::dpiScaled(12, opt, widget)); break; case PM_MenuTearoffHeight: - ret = int(QStyleHelper::dpiScaled(10.)); + ret = int(QStyleHelper::dpiScaled(10, opt, widget)); break; case PM_MenuScrollerHeight: - ret = int(QStyleHelper::dpiScaled(10.)); + ret = int(QStyleHelper::dpiScaled(10, opt, widget)); break; case PM_MenuDesktopFrameWidth: @@ -4609,22 +4609,22 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_HeaderMargin: - ret = int(QStyleHelper::dpiScaled(4.)); + ret = int(QStyleHelper::dpiScaled(4, opt, widget)); break; case PM_HeaderMarkSize: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16, opt, widget)); break; case PM_HeaderGripMargin: - ret = int(QStyleHelper::dpiScaled(4.)); + ret = int(QStyleHelper::dpiScaled(4, opt, widget)); break; case PM_HeaderDefaultSectionSizeHorizontal: - ret = int(QStyleHelper::dpiScaled(100.)); + ret = int(QStyleHelper::dpiScaled(100, opt, widget)); break; case PM_HeaderDefaultSectionSizeVertical: - ret = int(QStyleHelper::dpiScaled(30.)); + ret = int(QStyleHelper::dpiScaled(30, opt, widget)); break; case PM_TabBarScrollButtonWidth: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16, opt, widget)); break; case PM_LayoutLeftMargin: case PM_LayoutTopMargin: @@ -4646,13 +4646,13 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_DefaultTopLevelMargin: - ret = int(QStyleHelper::dpiScaled(11.)); + ret = int(QStyleHelper::dpiScaled(11, opt, widget)); break; case PM_DefaultChildMargin: - ret = int(QStyleHelper::dpiScaled(9.)); + ret = int(QStyleHelper::dpiScaled(9, opt, widget)); break; case PM_DefaultLayoutSpacing: - ret = int(QStyleHelper::dpiScaled(6.)); + ret = int(QStyleHelper::dpiScaled(6, opt, widget)); break; case PM_ToolBarIconSize: @@ -4660,7 +4660,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) ret = theme->themeHint(QPlatformTheme::ToolBarIconSize).toInt(); if (ret <= 0) - ret = int(QStyleHelper::dpiScaled(24.)); + ret = int(QStyleHelper::dpiScaled(24, opt, widget)); break; case PM_TabBarIconSize: @@ -4670,14 +4670,14 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid case PM_ButtonIconSize: case PM_SmallIconSize: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16, opt, widget)); break; case PM_IconViewIconSize: ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget); break; case PM_LargeIconSize: - ret = int(QStyleHelper::dpiScaled(32.)); + ret = int(QStyleHelper::dpiScaled(32, opt, widget)); break; case PM_ToolTipLabelFrameWidth: @@ -4685,10 +4685,10 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_CheckBoxLabelSpacing: case PM_RadioButtonLabelSpacing: - ret = int(QStyleHelper::dpiScaled(6.)); + ret = int(QStyleHelper::dpiScaled(6, opt, widget)); break; case PM_SizeGripSize: - ret = int(QStyleHelper::dpiScaled(13.)); + ret = int(QStyleHelper::dpiScaled(13, opt, widget)); break; case PM_MessageBoxIconSize: #ifdef Q_OS_MAC @@ -4697,7 +4697,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid } else #endif { - ret = int(QStyleHelper::dpiScaled(32.)); + ret = int(QStyleHelper::dpiScaled(32, opt, widget)); } break; case PM_TextCursorWidth: @@ -4708,7 +4708,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid break; case PM_TabCloseIndicatorWidth: case PM_TabCloseIndicatorHeight: - ret = int(QStyleHelper::dpiScaled(16.)); + ret = int(QStyleHelper::dpiScaled(16, opt, widget)); break; case PM_ScrollView_ScrollBarSpacing: ret = 2 * proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget); @@ -4720,7 +4720,7 @@ int QCommonStyle::pixelMetric(PixelMetric m, const QStyleOption *opt, const QWid ret = -proxy()->pixelMetric(QStyle::PM_MenuPanelWidth, opt, widget); break; case PM_TreeViewIndentation: - ret = int(QStyleHelper::dpiScaled(20.)); + ret = int(QStyleHelper::dpiScaled(20, opt, widget)); break; default: ret = 0; diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 3473ec7..e768cf3 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -759,7 +759,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, painter->drawRect(rect); QColor checkMarkColor = option->palette.text().color().darker(120); - const int checkMarkPadding = QStyleHelper::dpiScaled(3); + const int checkMarkPadding = QStyleHelper::dpiScaled(3, option, widget); if (checkbox->state & State_NoChange) { gradient = QLinearGradient(rect.topLeft(), rect.bottomLeft()); @@ -773,7 +773,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, painter->drawRect(rect.adjusted(checkMarkPadding, checkMarkPadding, -checkMarkPadding, -checkMarkPadding)); } else if (checkbox->state & (State_On)) { - QPen checkPen = QPen(checkMarkColor, QStyleHelper::dpiScaled(1.8)); + QPen checkPen = QPen(checkMarkColor, QStyleHelper::dpiScaled(1.8, option, widget)); checkMarkColor.setAlpha(210); painter->translate(-1, 0.5); painter->setPen(checkPen); @@ -3145,7 +3145,7 @@ int QFusionStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, co default: return QCommonStyle::pixelMetric(metric, option, widget); } - return QStyleHelper::dpiScaled(val); + return QStyleHelper::dpiScaled(val, option, widget); } /*! @@ -3337,7 +3337,7 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom break; case SC_SliderGroove: { QPoint grooveCenter = slider->rect.center(); - const int grooveThickness = QStyleHelper::dpiScaled(7); + const int grooveThickness = QStyleHelper::dpiScaled(7, option, widget); if (slider->orientation == Qt::Horizontal) { rect.setHeight(grooveThickness); if (slider->tickPosition & QSlider::TicksAbove) @@ -3364,7 +3364,7 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom int center = spinbox->rect.height() / 2; int fw = spinbox->frame ? 3 : 0; // Is drawn with 3 pixels width in drawComplexControl, independently from PM_SpinBoxFrameWidth int y = fw; - const int buttonWidth = QStyleHelper::dpiScaled(14); + const int buttonWidth = QStyleHelper::dpiScaled(14, option, widget); int x, lx, rx; x = spinbox->rect.width() - y - buttonWidth + 2; lx = fw; diff --git a/src/widgets/styles/qstylehelper.cpp b/src/widgets/styles/qstylehelper.cpp index 6024217..d6e37d5 100644 --- a/src/widgets/styles/qstylehelper.cpp +++ b/src/widgets/styles/qstylehelper.cpp @@ -40,13 +40,16 @@ #include #include #include +#include +#include #include #include #include #include #include #include - +#include +#include #include "qstylehelper_p.h" #include #include @@ -96,14 +99,64 @@ QString uniqueName(const QString &key, const QStyleOption *option, const QSize & return tmp; } -qreal dpiScaled(qreal value) +static QScreen *screenOfWidget(const QWidget *w) +{ + if (const QWindow *window = w->windowHandle()) + return window->screen(); + if (const QWidget *nativeParent = w->nativeParentWidget()) { + if (const QWindow *window = nativeParent->windowHandle()) + return window->screen(); + } + return QGuiApplication::primaryScreen(); +} + +static inline QScreen *screenOf(const QStyleOption *option) +{ + if (option && option->styleObject) { + if (option->styleObject->isWidgetType()) + return screenOfWidget(static_cast(option->styleObject)); + if (option->styleObject->inherits("QQuickStyleItem")) { + for (QObject *p = option->styleObject->parent(); p; p = p->parent()) { + if (p->isWindowType()) { + if (QScreen *screen = static_cast(p)->screen()) + return screen; + } + } + } + } + return QGuiApplication::primaryScreen(); +} + +static inline qreal dpiForObject(const QStyleOption *option = nullptr, + const QWidget *widget = nullptr) +{ + if (QCoreApplication::testAttribute(Qt::AA_Use96Dpi)) + return 96; + + // QHighDpiScaling uses a common DPI value for all screens. + if (QHighDpiScaling::isActive()) + return QHighDpiScaling::logicalDpi().first; + + if (QGuiApplicationPrivate::screen_list.size() == 1) + return QGuiApplicationPrivate::screen_list.first()->logicalDotsPerInchX(); + + if (const QScreen *screen = widget ? screenOfWidget(widget) : screenOf(option)) + return screen->logicalDotsPerInchX(); + + //PI has not been initialised, or it is being initialised. Give a default dpi + return 100; +} + +qreal dpiScaled(qreal value, const QStyleOption *option, const QWidget *widget) { #ifdef Q_OS_MAC + Q_UNUSED(widget) + Q_UNUSED(option) // On mac the DPI is always 72 so we should not scale it return value; #else - static const qreal scale = qreal(qt_defaultDpiX()) / 96.0; - return value * scale; + const qreal dpi = dpiForObject(option, widget); + return value * dpi / 96.0; #endif } diff --git a/src/widgets/styles/qstylehelper_p.h b/src/widgets/styles/qstylehelper_p.h index 88eb05f..fbff0a9 100644 --- a/src/widgets/styles/qstylehelper_p.h +++ b/src/widgets/styles/qstylehelper_p.h @@ -67,11 +67,12 @@ class QPixmap; class QStyleOptionSlider; class QStyleOption; class QWindow; +class QWidget; namespace QStyleHelper { QString uniqueName(const QString &key, const QStyleOption *option, const QSize &size); - qreal dpiScaled(qreal value); + qreal dpiScaled(qreal value, const QStyleOption *option = nullptr, const QWidget *widget = nullptr); #ifndef QT_NO_DIAL qreal angle(const QPointF &p1, const QPointF &p2); QPolygonF calcLines(const QStyleOptionSlider *dial); diff --git a/src/widgets/styles/qwindowsstyle.cpp b/src/widgets/styles/qwindowsstyle.cpp index e3bf286..81f0218 100644 --- a/src/widgets/styles/qwindowsstyle.cpp +++ b/src/widgets/styles/qwindowsstyle.cpp @@ -416,7 +416,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, widget)); ret = 0; @@ -462,7 +462,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, widget)), QApplication::globalStrut().width()); break; default: @@ -2320,8 +2320,8 @@ 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.)); + int minwidth = int(QStyleHelper::dpiScaled(75, opt, widget)); + int minheight = int(QStyleHelper::dpiScaled(23, opt, widget)); #ifndef QT_QWS_SMALL_PUSHBUTTON if (w < minwidth + defwidth && !btn->text.isEmpty()) diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index 8c91e3a..c861c74 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -2161,7 +2161,7 @@ QRect QWindowsVistaStyle::subControlRect(ComplexControl control, const QStyleOpt const int width = tb->rect.width(); const int buttonWidth = qRound(qreal(GetSystemMetrics(SM_CXSIZE)) * QWindowsStylePrivate::nativeMetricScaleFactor(widget) - - QStyleHelper::dpiScaled(4)); + - QStyleHelper::dpiScaled(4, option, widget)); const int frameWidth = proxy()->pixelMetric(PM_MdiSubWindowFrameWidth, option, widget); const bool sysmenuHint = (tb->titleBarFlags & Qt::WindowSystemMenuHint) != 0; @@ -2262,7 +2262,7 @@ int QWindowsVistaStyle::pixelMetric(PixelMetric metric, const QStyleOption *opti int ret = QWindowsVistaStylePrivate::fixedPixelMetric(metric); if (ret != QWindowsStylePrivate::InvalidMetric) - return int(QStyleHelper::dpiScaled(ret)); + return int(QStyleHelper::dpiScaled(ret, option, widget)); return QWindowsXPStyle::pixelMetric(metric, option, widget); } diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 4ce359a..500f20b 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -3320,7 +3320,8 @@ int QWindowsXPStyle::pixelMetric(PixelMetric pm, const QStyleOption *option, con break; case PM_SplitterWidth: - res = qMax(int(QStyleHelper::dpiScaled(5.)), QApplication::globalStrut().width()); + res = qMax(int(QStyleHelper::dpiScaled(5., option, widget)), + QApplication::globalStrut().width()); break; case PM_MdiSubWindowMinimizedWidth: @@ -3329,13 +3330,13 @@ int QWindowsXPStyle::pixelMetric(PixelMetric pm, const QStyleOption *option, con #ifndef QT_NO_TOOLBAR case PM_ToolBarHandleExtent: - res = int(QStyleHelper::dpiScaled(8.)); + res = int(QStyleHelper::dpiScaled(8., option, widget)); break; #endif // QT_NO_TOOLBAR case PM_DockWidgetSeparatorExtent: case PM_DockWidgetTitleMargin: - res = int(QStyleHelper::dpiScaled(4.)); + res = int(QStyleHelper::dpiScaled(4., option, widget)); break; case PM_ButtonShiftHorizontal: @@ -3420,7 +3421,7 @@ QRect QWindowsXPStyle::subControlRect(ComplexControl cc, const QStyleOptionCompl const bool isToolTitle = false; const int height = tb->rect.height(); const int width = tb->rect.width(); - const int buttonMargin = int(QStyleHelper::dpiScaled(4)); + const int buttonMargin = int(QStyleHelper::dpiScaled(4, option, widget)); const qreal factor = QWindowsStylePrivate::nativeMetricScaleFactor(widget); int buttonHeight = qRound(qreal(GetSystemMetrics(SM_CYSIZE)) * factor) - buttonMargin; -- 2.8.1.windows.1