summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
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/widgets/styles
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/widgets/styles')
-rw-r--r--src/widgets/styles/qcommonstyle.cpp3
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp3
2 files changed, 4 insertions, 2 deletions
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<const QStyleOptionTab *>(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()));