diff options
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 6 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 9b4a4bdc12..d41e80fad0 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -2472,8 +2472,10 @@ void QWidgetPrivate::setStyle_helper(QStyle *newStyle, bool propagate, bool } if (propagate) { - for (int i = 0; i < children.size(); ++i) { - QWidget *c = qobject_cast<QWidget*>(children.at(i)); + // We copy the list because the order may be modified + const QObjectList childrenList = children; + for (int i = 0; i < childrenList.size(); ++i) { + QWidget *c = qobject_cast<QWidget*>(childrenList.at(i)); if (c) c->d_func()->inheritStyle(); } diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index f38a124f29..0c35107157 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -72,7 +72,7 @@ #include <qtableview.h> #include <qtreewidget.h> #include <qabstractnativeeventfilter.h> - +#include <qproxystyle.h> #include <QtWidgets/QGraphicsView> #include <QtWidgets/QGraphicsProxyWidget> @@ -387,6 +387,7 @@ private slots: void touchEventSynthesizedMouseEvent(); + void styleSheetPropagation(); private: bool ensureScreenSize(int width, int height); QWidget *testWidget; @@ -9513,5 +9514,15 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() } } +void tst_QWidget::styleSheetPropagation() +{ + QTableView tw; + tw.setStyleSheet("background-color: red;"); + foreach (QObject *child, tw.children()) { + if (QWidget *w = qobject_cast<QWidget *>(child)) + QCOMPARE(w->style(), tw.style()); + } +} + QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" |