summaryrefslogtreecommitdiffstats
path: root/src/plugins/styles/mac/qmacstyle_mac.mm
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-03-19 12:09:40 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-03-21 19:41:23 +0000
commit4ac00ca901f1cbd503b858eb1e5ed19079c31f44 (patch)
tree1683e4257f37f901300388bb152cb0ee0efbd707 /src/plugins/styles/mac/qmacstyle_mac.mm
parenteaabd0c5450ad849e24878d38dd05d5b23d7eec3 (diff)
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 <axel.spoerl@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/plugins/styles/mac/qmacstyle_mac.mm')
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm5
1 files changed, 3 insertions, 2 deletions
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<const QStyleOptionTab *>(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<const QTabBar *>(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;