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; diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index cdd061f8d5..f324925607 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -2004,7 +2004,8 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon); } - proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, QPalette::WindowText); + proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, + widget ? widget->foregroundRole() : QPalette::WindowText); if (verticalTabs) p->restore(); diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index b325b5d8eb..54b7e3879a 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -4390,6 +4390,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q case CE_TabBarTabLabel: case CE_TabBarTabShape: if (const QStyleOptionTab *tab = qstyleoption_cast(opt)) { + const auto foregroundRole = w ? w->foregroundRole() : QPalette::WindowText; QRenderRule subRule = renderRule(w, opt, PseudoElement_TabBarTab); QRect r = positionRect(w, subRule, PseudoElement_TabBarTab, opt->rect, opt->direction); if (ce == CE_TabBarTabShape && subRule.hasDrawable() && tab->shape < QTabBar::TriangularNorth) { @@ -4397,7 +4398,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q return; } QStyleOptionTab tabCopy(*tab); - subRule.configurePalette(&tabCopy.palette, QPalette::WindowText, QPalette::Base); + subRule.configurePalette(&tabCopy.palette, foregroundRole, QPalette::Base); QFont oldFont = p->font(); if (subRule.hasFont) p->setFont(subRule.font.resolve(p->font()));