Cocoa: change background color of selected menu items

Change 582d221b29 caused a regression when drawing menu items in
e.g a QComboBox. After that change, QCocoaSystemSettings would set the
QPalette::Highlight color to [NSColor selectedMenuItemTextColor]. But
the Highlight color is the background color, not the text color. And we
also use [NSColor selectedMenuItemTextColor] as the QPalette::HighlightedText
color. The result is that highlighed menu items end up with the same
foreground and background color (white), which means that they "disappear".

The color that we used before the patch, alternateSelectedControlColor, could
be used, but has the downside that it doesn't follow the appearance color in
system settings (like it should, compared to native apps). And it's also slightly
to blue. But using keyboardFocusIndicatorColor seems like a perfect match.

Fixes: QTBUG-69500
Change-Id: I07f091a5130a7308525743948d2a435226658a6f
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Richard Moe Gustavsen 2018-09-05 10:03:00 +02:00
parent 5474f28c42
commit 8d3b9841e1
1 changed files with 5 additions and 1 deletions

View File

@ -169,7 +169,11 @@ QHash<QPlatformTheme::Palette, QPalette*> qt_mac_createRolePalettes()
// Cheap approximation for NSVisualEffectView (see deprecation note for selectedMenuItemTextColor)
selectedMenuItemColor = [[NSColor selectedContentBackgroundColor] highlightWithLevel:0.4];
} else {
selectedMenuItemColor = [NSColor selectedMenuItemTextColor];
// selectedMenuItemColor would presumably be the correct color to use as the background
// for selected menu items. But that color is always blue, and doesn't follow the
// appearance color in system preferences. So we therefore deliberatly choose to use
// keyboardFocusIndicatorColor instead, which appears to have the same color value.
selectedMenuItemColor = [NSColor keyboardFocusIndicatorColor];
}
pal.setBrush(QPalette::Highlight, qt_mac_toQColor(selectedMenuItemColor));
qc = qt_mac_toQColor([NSColor labelColor]);