From 4ac00ca901f1cbd503b858eb1e5ed19079c31f44 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Sat, 19 Mar 2022 12:09:40 +0100 Subject: QTabBar: let styles draw tab text with foreground role QTabBar::setTabTextColor's documentation and implementation suggests that the set color will always be used unless invalid, and that the foreground role is used otherwise. QTabBar then sets the foregroundRole palette entry to the specified color before calling the style. The intent is evidently that the tabTextColor is used no matter the foregroundRole (which by default is the role that contrasts with the background role). If the styles always paint the text with WindowText, then the tabTextColor gets ignored if the foregroundRole is not WindowText (perhaps because the backgroundRole is set to Base). Fix this by respecting the widget's foregroundRole when painting the tab label in the common style (which is the only style that implements drawControl for CE_TabBarTabLabel). QMacStyle and QStyleSheetStyle need to be adjusted to prepare the palette consistently with the logic in QTabBar. Pick-to: 6.3 6.2 Fixes: QTBUG-101456 Change-Id: I077a2034eebfe3f56cea28917494f4db01e48747 Reviewed-by: Axel Spoerl Reviewed-by: Richard Moe Gustavsen --- src/plugins/styles/mac/qmacstyle_mac.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/plugins/styles/mac/qmacstyle_mac.mm') diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm index 19181dde5c..3676a6ffb6 100644 --- a/src/plugins/styles/mac/qmacstyle_mac.mm +++ b/src/plugins/styles/mac/qmacstyle_mac.mm @@ -4098,6 +4098,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter case CE_TabBarTabLabel: if (const auto *tab = qstyleoption_cast(opt)) { QStyleOptionTab myTab = *tab; + const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText; const auto tabDirection = QMacStylePrivate::tabDirection(tab->shape); const bool verticalTabs = tabDirection == QMacStylePrivate::East || tabDirection == QMacStylePrivate::West; @@ -4111,11 +4112,11 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter if (!myTab.documentMode && (myTab.state & State_Selected) && (myTab.state & State_Active)) if (const auto *tabBar = qobject_cast(w)) if (!tabBar->tabTextColor(tabBar->currentIndex()).isValid()) - myTab.palette.setColor(QPalette::WindowText, Qt::white); + myTab.palette.setColor(foregroundRole, Qt::white); if (myTab.documentMode && isDarkMode()) { bool active = (myTab.state & State_Selected) && (myTab.state & State_Active); - myTab.palette.setColor(QPalette::WindowText, active ? Qt::white : Qt::gray); + myTab.palette.setColor(foregroundRole, active ? Qt::white : Qt::gray); } int heightOffset = 0; -- cgit v1.2.3