summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2023-06-07 12:28:48 +0200
committerAxel Spoerl <axel.spoerl@qt.io>2023-06-09 23:42:47 +0200
commitc4635c0d5822d0e95ceca867fffb9ba86a2b7bfe (patch)
tree8ab300ecabde40ed59308a285dce4b693214118c /src
parent1797f7946d27b873b34fa30b0856414e27e2daeb (diff)
QStyleSheetStyle: Default to foreground for unset brushes only
If a foreground style has been defined in the style sheet, QStyleSheetStyle populates its brushes for the color roles ButtonText, WindowText, Text, and the widget's foregroundRole with the foreground brush. PlaceholderText is set to the same brush with a modified color. That sets their resolve bits in QStyleSheeetStyle's palette and prevents these color roles from being inherited by the widget's palette - in contrast to all other brushes. This patch makes the brushes mentioned default to the widget's palette if they are set there. It adds a test in tst_QStyleSheetStyle. Fixes: QTBUG-93009 Pick-to: 6.6 6.5 Change-Id: Ie3df9dbd17b96fa72beee90792fc7eca1933cdbe Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index 22a5f718ce..06a49d8e0f 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -1465,6 +1465,16 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorRole fr, QPalette
p->setBrush(QPalette::AlternateBase, pal->alternateBackground);
}
+void setDefault(QPalette *palette, QPalette::ColorGroup group, QPalette::ColorRole role,
+ const QBrush &defaultBrush, const QWidget *widget)
+{
+ const QPalette &widgetPalette = widget->palette();
+ if (widgetPalette.isBrushSet(group, role))
+ palette->setBrush(group, role, widgetPalette.brush(group, role));
+ else
+ palette->setBrush(group, role, defaultBrush);
+}
+
void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const QWidget *w, bool embedded)
{
if (bg && bg->brush.style() != Qt::NoBrush) {
@@ -1486,15 +1496,15 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q
return;
if (pal->foreground.style() != Qt::NoBrush) {
- p->setBrush(cg, QPalette::ButtonText, pal->foreground);
- p->setBrush(cg, w->foregroundRole(), pal->foreground);
- p->setBrush(cg, QPalette::WindowText, pal->foreground);
- p->setBrush(cg, QPalette::Text, pal->foreground);
+ setDefault(p, cg, QPalette::ButtonText, pal->foreground, w);
+ setDefault(p, cg, w->foregroundRole(), pal->foreground, w);
+ setDefault(p, cg, QPalette::WindowText, pal->foreground, w);
+ setDefault(p, cg, QPalette::Text, pal->foreground, w);
QColor phColor(pal->foreground.color());
phColor.setAlpha((phColor.alpha() + 1) / 2);
QBrush placeholder = pal->foreground;
placeholder.setColor(phColor);
- p->setBrush(cg, QPalette::PlaceholderText, placeholder);
+ setDefault(p, cg, QPalette::PlaceholderText, placeholder, w);
}
if (pal->selectionBackground.style() != Qt::NoBrush)
p->setBrush(cg, QPalette::Highlight, pal->selectionBackground);