From 6ff07ec23b562d78f7fa19b5c6ada72724dc81a1 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 10 Nov 2021 15:04:58 +0100 Subject: [PATCH] macOS: make the slider knob big enough for BigSur and Monterey The slider is very touch friendly from macOS 11 on, and the knob is quite large. Give it some extra pixels, and adjust the test accordingly. Pick-to: 6.2 Task-number: QTBUG-98093 Change-Id: Iedf6db1081cdd4013ca29ce760aea1e0361b1123 Reviewed-by: Qt CI Bot Reviewed-by: Richard Moe Gustavsen --- src/plugins/styles/mac/qmacstyle_mac.mm | 4 ++++ tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 4515b2b0ed..12b8e0c2f1 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -844,6 +844,8 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QStyleOption return ret; } + const bool isBigSurOrAbove = QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur; + if (ct == QStyle::CT_CustomBase && widg) { #if QT_CONFIG(pushbutton) if (qobject_cast(widg)) @@ -1024,6 +1026,8 @@ static QSize qt_aqua_get_known_size(QStyle::ContentsType ct, const QStyleOption w = qt_mac_aqua_get_metric(HSliderHeight); if (sld->tickPosition != QSlider::NoTicks) w += qt_mac_aqua_get_metric(HSliderTickHeight); + else if (isBigSurOrAbove) + w += 3; } else { w = qt_mac_aqua_get_metric(VSliderWidth); if (sld->tickPosition != QSlider::NoTicks) diff --git a/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp b/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp index e9802cd716..fd784f9ced 100644 --- a/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp +++ b/tests/auto/widgets/styles/qmacstyle/tst_qmacstyle.cpp @@ -83,6 +83,10 @@ private: #define SIZE(x, y, z) \ ((size == QStyleHelper::SizeLarge) ? (x) : (size == QStyleHelper::SizeSmall) ? (y) : (z)) +static bool bigSurOrAbove() { + return QOperatingSystemVersion::current() >= QOperatingSystemVersion::MacOSBigSur; +} + void tst_QMacStyle::sizeHints_data() { QTest::addColumn("size"); @@ -133,7 +137,7 @@ void tst_QMacStyle::sizeHints() QCOMPARE(sh(&comboBox3).height(), SIZE(32, -1, -1)); QSlider slider1(Qt::Horizontal, &w); - QCOMPARE(sh(&slider1).height(), SIZE(15, 12, 10)); + QCOMPARE(sh(&slider1).height(), SIZE(bigSurOrAbove() ? 18 : 15, 12, 10)); slider1.setTickPosition(QSlider::TicksAbove); QCOMPARE(sh(&slider1).height(), SIZE(24, 17, 16)); // Builder @@ -142,7 +146,7 @@ void tst_QMacStyle::sizeHints() QCOMPARE(sh(&slider1).height(), SIZE(24, 17, 16)); // Builder slider1.setTickPosition(QSlider::TicksBothSides); - QVERIFY(sh(&slider1).height() > SIZE(15, 12, 10)); // common sense + QVERIFY(sh(&slider1).height() > SIZE(bigSurOrAbove() ? 18 : 15, 12, 10)); // common sense QPushButton ok1("OK", &w); QPushButton cancel1("Cancel", &w);