From b749163bb81c1a5e46ec14fa0fecdbced1a7ed85 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 13 Jan 2022 13:43:02 +0100 Subject: Add test case for style sheet selectors for enum properties In Qt 5, such selectors have to use the integer value of the enum value. Using the enum value name does not work. In Qt 6, such selectors must use the enum value by name, using the integer does not work. It's not clear yet what changed, possible a side effect of the changes and improvements in the meta object system and QVariant in Qt 6. So for now, document the difference in behavior in a test. Pick-to: 6.2 6.3 5.15 Task-number: QTBUG-99642 Change-Id: I96e0280b191b8ca06b16a97ab3ed367e9a8f43a0 Reviewed-by: Oliver Eftevaag Reviewed-by: Doris Verria Reviewed-by: Axel Spoerl --- .../qstylesheetstyle/tst_qstylesheetstyle.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp index 272c175042..6409a669fe 100644 --- a/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp +++ b/tests/auto/widgets/styles/qstylesheetstyle/tst_qstylesheetstyle.cpp @@ -129,6 +129,8 @@ private slots: void QTBUG36933_brokenPseudoClassLookup(); void styleSheetChangeBeforePolish(); void placeholderColor(); + void enumPropertySelector_data(); + void enumPropertySelector(); //at the end because it mess with the style. void widgetStyle(); void appStyle(); @@ -2340,6 +2342,42 @@ void tst_QStyleSheetStyle::placeholderColor() QCOMPARE(le2.palette().placeholderText(), red); } +void tst_QStyleSheetStyle::enumPropertySelector_data() +{ + QTest::addColumn("styleSheet"); + + QTest::addRow("Enum value") << R"(QToolButton[popupMode=MenuButtonPopup] { padding-right: 40px; })"; + QTest::addRow("Int value") << R"(QToolButton[popupMode="1"] { padding-right: 40px; })"; +} + +void tst_QStyleSheetStyle::enumPropertySelector() +{ + QFETCH(QString, styleSheet); + + QToolButton button; + QMenu menu; + menu.addAction("Action1"); + QPixmap pm(50, 50); + pm.fill(Qt::red); + button.setIcon(pm); + button.setMenu(&menu); + button.setPopupMode(QToolButton::MenuButtonPopup); + + button.show(); + const QSize unstyledSizeHint = button.sizeHint(); + + qApp->setStyleSheet(styleSheet); + const QSize styledSizeHint = button.sizeHint(); + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QEXPECT_FAIL("Enum value", "In Qt 5, style sheet selectors have to use integer enum values", Continue); +#else + QEXPECT_FAIL("Int value", "In Qt 6, style sheet selectors must use the enum value name", Continue); +#endif + + QVERIFY(styledSizeHint.width() > unstyledSizeHint.width()); +} + void tst_QStyleSheetStyle::iconSizes_data() { QTest::addColumn("styleSheet"); -- cgit v1.2.3