diff options
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 20 | ||||
-rw-r--r-- | tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp | 27 |
2 files changed, 42 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); diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 39a568008a..ef26351b39 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -121,6 +121,8 @@ private slots: void iconSizes_data(); void iconSizes(); + void inheritWidgetPalette_data(); + void inheritWidgetPalette(); private: static QColor COLOR(const QWidget &w) @@ -2464,6 +2466,31 @@ void tst_QStyleSheetStyle::iconSizes() QCOMPARE(button.iconSize(), iconSize); } +void tst_QStyleSheetStyle::inheritWidgetPalette_data() +{ + QTest::addColumn<const QString>("styleSheet"); + QTest::addColumn<const QColor>("phColorPalette"); + + QTest::addRow("blueAndGreen") << "QLineEdit {color: rgb(0,0,255);}" << QColor(Qt::green); + QTest::addRow("emptyStyleSheet") << QString() << QColor(Qt::green); + +} + +void tst_QStyleSheetStyle::inheritWidgetPalette() +{ + QFETCH(const QString, styleSheet); + QFETCH(const QColor, phColorPalette); + + QLineEdit edit; + QPalette palette = edit.palette(); + palette.setBrush(QPalette::PlaceholderText, phColorPalette); + edit.setPalette(palette); + edit.setStyleSheet(styleSheet); + const QColor phColor = edit.palette().placeholderText().color(); + + QCOMPARE(phColor, phColorPalette); +} + QTEST_MAIN(tst_QStyleSheetStyle) #include "tst_qstylesheetstyle.moc" |