From 74acbcc9f31aa2c64d076e1157979537d90d3f6d Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Fri, 28 Aug 2020 16:55:25 +0200 Subject: 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 --- src/quickcontrols2/qquickstyleplugin.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/quickcontrols2/qquickstyleplugin.cpp') diff --git a/src/quickcontrols2/qquickstyleplugin.cpp b/src/quickcontrols2/qquickstyleplugin.cpp index 657b31fc..f211d4b0 100644 --- a/src/quickcontrols2/qquickstyleplugin.cpp +++ b/src/quickcontrols2/qquickstyleplugin.cpp @@ -41,7 +41,6 @@ #include #include #include - #include QT_BEGIN_NAMESPACE @@ -57,17 +56,24 @@ QQuickStylePlugin::~QQuickStylePlugin() { } -QString QQuickStylePlugin::name() const -{ - return QString(); -} - void QQuickStylePlugin::registerTypes(const char *uri) { qCDebug(lcStylePlugin).nospace() << "registerTypes called with uri " << uri << "; plugin name is " << name(); - if (!QQuickTheme::instance()) + auto theme = QQuickTheme::instance(); + if (!theme) { qWarning() << "QtQuick.Controls must be imported before importing" << baseUrl().toString(); + return; + } + + if (name() != QQuickStyle::name()) { + qCDebug(lcStylePlugin).nospace() << "theme does not belong to current style (" + << QQuickStyle::name() << "); not calling initializeTheme()"; + return; + } + + qCDebug(lcStylePlugin) << "theme has not been initialized; calling initializeTheme()"; + initializeTheme(theme); } void QQuickStylePlugin::unregisterTypes() -- cgit v1.2.3