diff options
author | Doris Verria <doris.verria@qt.io> | 2022-10-17 20:48:58 +0200 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2022-10-19 06:07:15 +0200 |
commit | 0709af1c02a653f3121c76ae7879cc64b2e246b7 (patch) | |
tree | 41893832bff4b46cba605ff9d1c1ad0f36819dfa /src/plugins/styles | |
parent | 9a5a31268e1fc1c86796dcf7f9ab757c4a599a49 (diff) |
QMacStyle: Set NSControlStateValueOn for selected tabs
We draw tab buttons as NSButtons of type PushOnPushOff. To draw a
selected tab, we used state ON (NSControlStateValueOn), which gives it
the accent color, and state OFF for non-selected tabs. To draw a
selected and pressed tab, we use state OFF and set highlight:
depending on isPressed.
This worked fine up until macOS 11 because when setting highlight to
true the push button would draw the accent color no matter the state.
In macOS 12, things are different. A highlighted NSButton doesn't draw
the accent color anymore, but rather a gray background.
So when we draw a selected tab using NSControlStateValueOn (blue/accent
color) and then press it (state changes to NSControlStateValueOff), the
tab will change color from accent/blue to gray. The text remains white,
so it's not clearly visible.
To fix, set the NSControlStateValueOn for selected, pressed tabs on
macOS 12, so the background color doesn't change when pressing on a
selected tab.
Fixes: QTBUG-101000
Pick-to: 6.2 6.4
Change-Id: Iaf48a7e2ae536c7c591578bb3c1065bd0e29b2e1
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/styles')
-rw-r--r-- | src/plugins/styles/mac/qmacstyle_mac.mm | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index c66131fdcd..d56b38a0d6 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -3935,8 +3935,13 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter pb.enabled = isEnabled; [pb highlight:isPressed]; + // Set off state when inactive. See needsInactiveHack for when it's selected - pb.state = (isActive && isSelected && !isPressed) ? NSControlStateValueOn : NSControlStateValueOff; + // On macOS 12, don't set the Off state for selected tabs as it draws a gray backgorund even when highlighted + if (QOperatingSystemVersion::current() > QOperatingSystemVersion::MacOSBigSur) + pb.state = (isActive && isSelected) ? NSControlStateValueOn : NSControlStateValueOff; + else + pb.state = (isActive && isSelected && !isPressed) ? NSControlStateValueOn : NSControlStateValueOff; const auto drawBezelBlock = ^(CGContextRef ctx, const CGRect &r) { CGContextClipToRect(ctx, opt->rect.toCGRect()); |