summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2021-12-30 09:06:10 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2022-01-22 15:18:03 +0100
commita47b3cbef67a1dcc25ecf1b367df86654a884cbe (patch)
tree820a9052f65b2295107d1a9ffbb2e3fbac7612b4 /src/plugins/styles
parent8576b7aab4c4582dff05cc4d3962c848ba32f947 (diff)
QMacStyle: use the 'momentary push in' type for push buttons
In the past, we were using different hacks to emulate the 'default' button and a normal button (and them in a pressed/not pressed active/non-active states). In macOS 12 old trick stopped working and UI looks a bit different: non-default buttons never get accent color even if pressed. Instead of relying on a combination of 'push on-push off' type's states and highlight, we can use the 'momentary push in' (highlighted == YES gives an impression of a pressed button) + setting a key equivalent (thanks to Tor Arne for the hint) gives the desired 'default button' look. Since we (re)use NSButton to render tab items, the 'momentary push in' button type breaks the tab. Temporary restore the old 'push on/push off' type if rendering a tab. Fixes: QTBUG-99743 Change-Id: I54b11c1a35373292ecf0bcd5cf7b4ea4203cc031 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> (cherry picked from commit cd446a7e250671c8994ee32395fe20a59d768466)
Diffstat (limited to 'src/plugins/styles')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index 58eb7735fe..86118b79cd 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -1680,8 +1680,8 @@ bool QMacStylePrivate::CocoaControl::getCocoaButtonTypeAndBezelStyle(NSButtonTyp
*bezelStyle = NSShadowlessSquareBezelStyle;
break;
case Button_PushButton:
- *buttonType = NSPushOnPushOffButton;
- *bezelStyle = NSRoundedBezelStyle;
+ *buttonType = NSButtonTypeMomentaryPushIn;
+ *bezelStyle = NSBezelStyleRounded;
break;
default:
return false;
@@ -3725,8 +3725,15 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
pb.frame = frameRect.toCGRect();
pb.enabled = isEnabled;
+
+ // With the 'momentary push in' type this gives an impression of a
+ // button in a 'pressed' state (the 'momentary push in' does
+ // not show its state otherwise):
[pb highlight:isPressed];
- pb.state = isHighlighted && !isPressed ? NSOnState : NSOffState;
+ // 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];
});
@@ -3768,16 +3775,22 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
const bool hasText = !btn.text.isEmpty();
const bool isActive = btn.state & State_Active;
const bool isPressed = btn.state & State_Sunken;
+ const bool isDefault = (btn.features & QStyleOptionButton::DefaultButton && !d->autoDefaultButton)
+ || d->autoDefaultButton == btn.styleObject;
const auto ct = cocoaControlType(&btn, w);
if (!hasMenu && ct != QMacStylePrivate::Button_SquareButton) {
- if (isPressed
- || (isActive && isEnabled
- && ((btn.state & State_On)
- || ((btn.features & QStyleOptionButton::DefaultButton) && !d->autoDefaultButton)
- || d->autoDefaultButton == btn.styleObject)))
- btn.palette.setColor(QPalette::ButtonText, Qt::white);
+ if (isPressed || (isActive && isEnabled && ((btn.state & State_On) || isDefault)))
+ btn.palette.setColor(QPalette::ButtonText, Qt::white);
+ }
+
+ if (!isDarkMode() && QOperatingSystemVersion::current() > QOperatingSystemVersion::MacOSBigSur) {
+ if (!isDefault && !(btn.state & State_On)) {
+ // On macOS 12 it's a gray button, white text color (if set in the
+ // previous statement) would be almost invisible.
+ btn.palette.setColor(QPalette::ButtonText, Qt::black);
+ }
}
if ((!hasIcon && !hasMenu) || (hasIcon && !hasText)) {
@@ -3955,6 +3968,13 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
}
pb.frame = frameRect.toCGRect();
+ if (!isPopupButton) {
+ // Note: these days we use 'momentary push in' for Button_PushButton,
+ // but tabs are also rendered using NSButton/ButtonPushButton, and
+ // here we need 'push on/off' to make it work (tab highlight colors).
+ pb.buttonType = NSButtonTypePushOnPushOff;
+ }
+
pb.enabled = isEnabled;
[pb highlight:isPressed];
// Set off state when inactive. See needsInactiveHack for when it's selected