From a68acbd0cf32cbe03b0c45fb0a4eccfe9d69742d Mon Sep 17 00:00:00 2001 From: Doris Verria Date: Mon, 17 Oct 2022 20:48:58 +0200 Subject: [PATCH] QMacStyle: Set NSControlStateValueOn for selected tabs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: Iaf48a7e2ae536c7c591578bb3c1065bd0e29b2e1 Reviewed-by: Tor Arne Vestbø (cherry picked from commit 0709af1c02a653f3121c76ae7879cc64b2e246b7) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/styles/mac/qmacstyle_mac.mm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index b60fc2f7ef7..1f15e6a830d 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());