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>
This commit is contained in:
parent
715a6c3908
commit
84d4b21f69
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user