aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/styleimports/tst_styleimports.cpp
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-08-28 16:55:25 +0200
committerMitch Curtis <mitch.curtis@qt.io>2020-09-24 13:48:39 +0200
commit74acbcc9f31aa2c64d076e1157979537d90d3f6d (patch)
treec896835ef345e8663aee2b6bf4b13e5779a6fd58 /tests/auto/styleimports/tst_styleimports.cpp
parent6059a7765b123a6f3fb221db9674a995bae1881c (diff)
Fix fallback styles overwriting themes
In Qt 5, QtQuickControls2Plugin::registerTypes() was responsible for calling initializeTheme() on each style plugin. Now that we delegate more work to the QML engine, each style plugin calls initializeTheme() via registerTypes(). To avoid fallback styles overwriting font and palette data set by the current style, we need to check if the theme has been intialized before calling initializeTheme(). To do this, we add a static "themeInitialized" bool that QQuickStylePlugin sets to true after calling intializeTheme() for the first time. It checks this value and avoids calling intializeTheme() if it's true. We also need to make QQuickStylePlugin ensure that the theme it's initializing belongs to the current style. Fixes: QTBUG-86303 Change-Id: Ie65e646677c78622829f4949c41cb79204cf5786 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto/styleimports/tst_styleimports.cpp')
-rw-r--r--tests/auto/styleimports/tst_styleimports.cpp47
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/auto/styleimports/tst_styleimports.cpp b/tests/auto/styleimports/tst_styleimports.cpp
index 8b47dee7..fa524098 100644
--- a/tests/auto/styleimports/tst_styleimports.cpp
+++ b/tests/auto/styleimports/tst_styleimports.cpp
@@ -43,6 +43,7 @@
#include <QtQuick/qquickwindow.h>
#include <QtQuickControls2/qquickstyle.h>
#include <QtQuickControls2/private/qquickstyle_p.h>
+#include <QtQuickControls2Impl/private/qquickiconlabel_p.h>
#include "../shared/util.h"
@@ -62,6 +63,9 @@ private slots:
void importStyleWithoutControls_data();
void importStyleWithoutControls();
+
+ void fallbackStyleShouldNotOverwriteTheme_data();
+ void fallbackStyleShouldNotOverwriteTheme();
};
void tst_StyleImports::initTestCase()
@@ -151,6 +155,7 @@ void tst_StyleImports::select()
QQuickStyle::setFallbackStyle(fallback);
QQmlEngine engine;
+ engine.addImportPath(QLatin1String(":/"));
engine.addImportPath(directory());
engine.addImportPath(dataDirectory());
QQmlComponent component(&engine);
@@ -185,7 +190,7 @@ void tst_StyleImports::platformSelectors()
QQmlApplicationEngine engine;
engine.addImportPath(dataDirectory());
- engine.load(testFileUrl("platformSelectors.qml"));
+ engine.load(testFileUrl("applicationWindowWithButton.qml"));
QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
QVERIFY(window);
@@ -241,6 +246,46 @@ void tst_StyleImports::importStyleWithoutControls()
QTRY_VERIFY(success);
}
+void tst_StyleImports::fallbackStyleShouldNotOverwriteTheme_data()
+{
+ QTest::addColumn<QString>("style");
+ QTest::addColumn<QString>("fallbackStyle");
+ QTest::addColumn<QColor>("expectedContentItemColor");
+
+ QTest::addRow("style=Fusion,fallbackStyle=Material")
+ << QString::fromLatin1("Fusion") << QString::fromLatin1("Material") << QColor::fromRgb(0x252525);
+ QTest::addRow("style=ResourceStyle,fallbackStyle=Material")
+ << QString::fromLatin1("ResourceStyle") << QString::fromLatin1("Material") << QColor("salmon");
+}
+
+void tst_StyleImports::fallbackStyleShouldNotOverwriteTheme()
+{
+ QFETCH(QString, style);
+ QFETCH(QString, fallbackStyle);
+ QFETCH(QColor, expectedContentItemColor);
+
+ QQuickStyle::setStyle(style);
+ QQuickStyle::setFallbackStyle(fallbackStyle);
+
+ QQmlApplicationEngine engine;
+ engine.addImportPath(QLatin1String(":/"));
+ engine.addImportPath(dataDirectory());
+ engine.load(testFileUrl("applicationWindowWithButton.qml"));
+ QVERIFY(!engine.rootObjects().isEmpty());
+ QQuickWindow *window = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
+ QVERIFY(window);
+
+ QObject *button = window->property("button").value<QObject*>();
+ QVERIFY(button);
+
+ QQuickIconLabel *contentItem = button->property("contentItem").value<QQuickIconLabel*>();
+ QVERIFY(contentItem);
+
+ // For example: the Fusion style provides Button.qml, so the Button's text color
+ // should be that of QPalette::ButtonText from QQuickFusionTheme.
+ QCOMPARE(contentItem->color(), expectedContentItemColor);
+}
+
QTEST_MAIN(tst_StyleImports)
#include "tst_styleimports.moc"