diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 757835f3aca..181122acb48 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3722,9 +3722,14 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter // not show its state otherwise): [pb highlight:isPressed]; - // For default/checked button this will give the required - // button accent color: - pb.keyEquivalent = isHighlighted ? @"\r" : @""; + + if (cw.type == QMacStylePrivate::Button_SquareButton) { + pb.state = isHighlighted && !isPressed ? NSControlStateValueOn : NSControlStateValueOff; + } else { + // For default/checked button this will give the required + // button accent color: + pb.keyEquivalent = isHighlighted ? @"\r" : @""; + } d->drawNSViewInRect(pb, frameRect, p, ^(CGContextRef, const CGRect &r) { [pb.cell drawBezelWithFrame:r inView:pb.superview]; diff --git a/tests/baseline/widgets/tst_baseline_widgets.cpp b/tests/baseline/widgets/tst_baseline_widgets.cpp index b0a86ec8c35..34f9f745145 100644 --- a/tests/baseline/widgets/tst_baseline_widgets.cpp +++ b/tests/baseline/widgets/tst_baseline_widgets.cpp @@ -45,6 +45,8 @@ private slots: void tst_QPushButton_data(); void tst_QPushButton(); + void tst_QPushButtonSquare(); + void tst_QProgressBar_data(); void tst_QProgressBar(); @@ -198,6 +200,29 @@ void tst_Widgets::tst_QPushButton() testButton->setDown(false); } +void tst_Widgets::tst_QPushButtonSquare() +{ + QVBoxLayout layout; + + QPushButton button(testWindow()); + button.setText(QLatin1String("Square")); + const auto sizeHint = button.sizeHint().width(); + // Depending on the current QStyle, this may result in + // a different button look - on macOS it will look as + // a toolbutton: + button.setFixedSize(sizeHint, sizeHint); + + layout.addWidget(&button); + testWindow()->setLayout(&layout); + + takeStandardSnapshots(); + + button.setCheckable(true); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "square_unchecked"); + button.setChecked(true); + QBASELINE_CHECK_DEFERRED(takeSnapshot(), "square_checked"); +} + void tst_Widgets::tst_QProgressBar_data() { QTest::addColumn("orientation");