diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index a5ad101201..95d38c4882 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2575,7 +2575,16 @@ void QWidget::setStyleSheet(const QString& styleSheet) } if (proxy) { // style sheet update - if (d->polished) + bool repolish = d->polished; + if (!repolish) { + const auto childWidgets = findChildren(); + for (auto child : childWidgets) { + repolish = child->d_func()->polished; + if (repolish) + break; + } + } + if (repolish) proxy->repolish(this); return; } diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 27500173c8..a4ce5ac77e 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -77,6 +77,7 @@ private slots: void cleanup(); void repolish(); void repolish_without_crashing(); + void repolish_children(); void numinstances(); void widgetsBeforeAppStyleSheet(); void widgetsAfterAppStyleSheet(); @@ -438,6 +439,19 @@ void tst_QStyleSheetStyle::repolish_without_crashing() QCOMPARE(COLOR(*label), QColor(Qt::red)); } +void tst_QStyleSheetStyle::repolish_children() +{ + QWidget parent; + parent.setStyleSheet("QPushButton { color: red; background: white }"); + QPushButton p2(&parent); + // a layout would call show, triggering a polish of the child while + // the parent on which the style sheet is set remains unpolished + p2.show(); + QCOMPARE(BACKGROUND(p2), Qt::white); + parent.setStyleSheet("QPushButton { color: red; background: red }"); + QCOMPARE(BACKGROUND(p2), Qt::red); +} + void tst_QStyleSheetStyle::widgetStyle() { qApp->setStyleSheet(QString());