summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorAxel Spoerl <axel.spoerl@qt.io>2022-11-28 11:47:24 +0100
committerAxel Spoerl <axel.spoerl@qt.io>2022-11-30 22:11:12 +0100
commit84d4b21f697f6be064a9baef628d313a7f059ac2 (patch)
tree0e87bf03c998df4c989f1ab774a0eda00dc749ee /tests/auto
parent715a6c390874f9a53a21ad66bd5c37a513c88199 (diff)
Stabilize tst_QComboBox::setPalette() with simple palettes
The test function tst_QComboBox::setPalette() tests if the QComboBox correctly inherits its palette to its QLineEdit child, by directly comparing both palettes after a palette change on the QComboBox. If the application palette for both widget types contains brushes which are either pixmap based or the resolve mask prevents them from being copied, the direct palette comparison between parent and child fails, despite of a correct propagation. This patch sets a simple gray application palette for QComboBox and QLineEdit at the beginning of the test. The QSKIP for macOS is removed, because using simple palettes solves both issues. Change-Id: I61d509745377306d6f8331dfc1ac189fc58cdedb Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index 00874882df..5b9f8f4f43 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -451,11 +451,19 @@ void tst_QComboBox::setEditable()
void tst_QComboBox::setPalette()
{
-#ifdef Q_OS_MAC
- if (QApplication::style()->inherits("QMacStyle")) {
- QSKIP("This test doesn't make sense for pixmap-based styles");
- }
-#endif
+ // If (a) Palettes are pixmap based and/or (b) contain color groups/roles which the
+ // resolve mask prevents from being copied, the direct comparison of the inherited
+ // palette and the parent palette will fail.
+ // To prevent that, set a simple gray system palette for QComboBox and QLineEdit
+ const QPalette comboBoxPalette = qApp->palette("QComboBox");
+ const QPalette lineEditPalette = qApp->palette("QLineEdit");
+ auto guard = qScopeGuard([&]{
+ qApp->setPalette(comboBoxPalette, "QComboBox");
+ qApp->setPalette(lineEditPalette, "QLineEdit");
+ });
+ qApp->setPalette(QPalette(Qt::gray), "QComboBox");
+ qApp->setPalette(QPalette(Qt::gray), "QLineEdit");
+
TestWidget topLevel;
topLevel.show();
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
@@ -463,16 +471,15 @@ void tst_QComboBox::setPalette()
QPalette pal = testWidget->palette();
pal.setColor(QPalette::Base, Qt::red);
testWidget->setPalette(pal);
- testWidget->setEditable(!testWidget->isEditable());
+ testWidget->setEditable(true);
pal.setColor(QPalette::Base, Qt::blue);
testWidget->setPalette(pal);
- const QObjectList comboChildren = testWidget->children();
- for (int i = 0; i < comboChildren.size(); ++i) {
- QObject *o = comboChildren.at(i);
- if (o->isWidgetType()) {
- QCOMPARE(((QWidget*)o)->palette(), pal);
+ const QObjectList &comboChildren = testWidget->children();
+ for (auto *child : comboChildren) {
+ if (auto *widget = qobject_cast<QWidget *>(child)) {
+ QCOMPARE(widget->palette(), pal);
}
}