diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 2d877fbe5ac..2ba860c22ee 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -1098,6 +1098,15 @@ void tst_QWidget::palettePropagation() QCOMPARE( newPalette, grandChildWidget->palette() ); } +bool waitForPolished(QWidgetList widgets) +{ + for (const auto *widget : widgets) { + if (!QTest::qWaitFor([widget]{ return widget->testAttribute(Qt::WA_WState_Polished); })) + return false; + } + return true; +} + void tst_QWidget::palettePropagation2() { if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) @@ -1109,73 +1118,67 @@ void tst_QWidget::palettePropagation2() // palette.setColor(QPalette::Text, QColor(21, 22, 23)); // qApp->setPalette(palette, "QPropagationTestWidget"); - QScopedPointer root(new QWidget); - root->setObjectName(QLatin1String("palettePropagation2")); - root->setWindowTitle(root->objectName()); - root->resize(200, 200); - QWidget *child0 = new QWidget(root.data()); - QWidget *child1 = new QWidget(child0); - QWidget *child2 = new QPropagationTestWidget(child1); - QWidget *child3 = new QWidget(child2); - QWidget *child4 = new QWidget(child3); - QWidget *child5 = new QWidget(child4); - root->show(); - QVERIFY(QTest::qWaitForWindowExposed(root.data())); + QWidget root; + root.setObjectName(QTest::currentTestFunction()); + root.setWindowTitle(root.objectName()); + root.resize(200, 200); + + QWidget *parent = &root; + static constexpr int propagationIndex = 2; + QWidgetList children; + for (int i = 0; i < 6; ++i) { + QWidget *w = (propagationIndex == i) ? new QPropagationTestWidget(parent) : new QWidget(parent); + w->setObjectName(QString("Widget-%1").arg(i)); + children << w; + parent = w; + } + + root.show(); + QVERIFY(QTest::qWaitForWindowExposed(&root)); // These colors are unlikely to be imposed on the default palette of // QWidget ;-). - QColor sysPalText(21, 22, 23); - QColor sysPalToolTipBase(12, 13, 14); - QColor overridePalText(42, 43, 44); - QColor overridePalToolTipBase(45, 46, 47); - QColor sysPalButton(99, 98, 97); + static constexpr QColor sysPalText(21, 22, 23); + static constexpr QColor sysPalToolTipBase(12, 13, 14); + static constexpr QColor overridePalText(42, 43, 44); + static constexpr QColor overridePalToolTipBase(45, 46, 47); + static constexpr QColor sysPalButton(99, 98, 97); // Check that only the application fonts apply. - QPalette appPal = QApplication::palette(); - QCOMPARE(root->palette(), appPal); - QCOMPARE(child0->palette(), appPal); - QCOMPARE(child1->palette(), appPal); - QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); - QCOMPARE(child2->palette().color(QPalette::Text), sysPalText); - QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); - QCOMPARE(child3->palette().color(QPalette::Text), sysPalText); - QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child4->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); - QCOMPARE(child4->palette().color(QPalette::Text), sysPalText); - QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child5->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); - QCOMPARE(child5->palette().color(QPalette::Text), sysPalText); - QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); + const QPalette &appPal = QApplication::palette(); + waitForPolished(children); + QCOMPARE(root.palette(), appPal); + QCOMPARE(children.at(0)->palette(), appPal); + QCOMPARE(children.at(1)->palette(), appPal); - // Set child0's Text, and set ToolTipBase on child4. + for (int i = 2; i < children.count(); i++) { + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); + QCOMPARE(children.at(i)->palette().color(QPalette::Text), sysPalText); + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); + } + + // Set children.at(0)'s Text, and set ToolTipBase on children.at(4). QPalette textPalette; textPalette.setColor(QPalette::Text, overridePalText); - child0->setPalette(textPalette); + children.at(0)->setPalette(textPalette); QPalette toolTipPalette; toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase); - child4->setPalette(toolTipPalette); + children.at(4)->setPalette(toolTipPalette); // Check that the above settings propagate correctly. - QCOMPARE(root->palette(), appPal); - QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); - QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); - QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); - QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); - QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); - QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child5->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); - QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); + waitForPolished(children); + QCOMPARE(root.palette(), appPal); + + for (int i = 0; i < children.count(); i++) { + QCOMPARE(children.at(i)->palette().color(QPalette::Text), overridePalText); + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); + if (i <= 1) + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); + else if (i <= 3) + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), sysPalToolTipBase); + else if (i <= 5) + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); + } // Replace the app palette for child2. Button should propagate but Text // should still be ignored. The previous ToolTipBase setting is gone. @@ -1184,25 +1187,20 @@ void tst_QWidget::palettePropagation2() QApplication::setPalette(buttonPalette, "QPropagationTestWidget"); // Check that the above settings propagate correctly. - QCOMPARE(root->palette(), appPal); - QCOMPARE(child0->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); - QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child1->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); - QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); - QCOMPARE(child2->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child2->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); - QCOMPARE(child2->palette().color(QPalette::ToolTipText), sysPalButton); - QCOMPARE(child3->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child3->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); - QCOMPARE(child3->palette().color(QPalette::ToolTipText), sysPalButton); - QCOMPARE(child4->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); - QCOMPARE(child4->palette().color(QPalette::ToolTipText), sysPalButton); - QCOMPARE(child5->palette().color(QPalette::Text), overridePalText); - QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); - QCOMPARE(child5->palette().color(QPalette::ToolTipText), sysPalButton); + waitForPolished(children); + QCOMPARE(root.palette(), appPal); + + for (int i = 0; i < children.count(); i++) { + QCOMPARE(children.at(i)->palette().color(QPalette::Text), overridePalText); + if (i <= 1) + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText)); + if (i <= 3) + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase)); + else if (i < children.count()) { + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), overridePalToolTipBase); + QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), sysPalButton); + } + } } /*!