aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickcontrols2
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 /src/quickcontrols2
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 'src/quickcontrols2')
-rw-r--r--src/quickcontrols2/qquickstyle.cpp3
-rw-r--r--src/quickcontrols2/qquickstyleplugin.cpp20
-rw-r--r--src/quickcontrols2/qquickstyleplugin_p.h3
3 files changed, 18 insertions, 8 deletions
diff --git a/src/quickcontrols2/qquickstyle.cpp b/src/quickcontrols2/qquickstyle.cpp
index fd81d1dd..ec0b5e48 100644
--- a/src/quickcontrols2/qquickstyle.cpp
+++ b/src/quickcontrols2/qquickstyle.cpp
@@ -142,6 +142,9 @@ struct QQuickStyleSpec
void setFallbackStyle(const QString &fallback, const QByteArray &method)
{
+ if (!fallback.isEmpty())
+ qCDebug(lcQtQuickControlsStyle) << "fallback style" << fallback << "set on QQuickStyleSpec via" << method;
+
fallbackStyle = fallback;
fallbackMethod = method;
}
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 <QtCore/qloggingcategory.h>
#include <QtQml/qqmlengine.h>
#include <QtQml/qqmlfile.h>
-
#include <QtQuickTemplates2/private/qquicktheme_p_p.h>
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()
diff --git a/src/quickcontrols2/qquickstyleplugin_p.h b/src/quickcontrols2/qquickstyleplugin_p.h
index 37d070db..1a941aa7 100644
--- a/src/quickcontrols2/qquickstyleplugin_p.h
+++ b/src/quickcontrols2/qquickstyleplugin_p.h
@@ -63,7 +63,8 @@ public:
explicit QQuickStylePlugin(QObject *parent = nullptr);
~QQuickStylePlugin();
- virtual QString name() const;
+ virtual QString name() const = 0;
+ virtual void initializeTheme(QQuickTheme *theme) = 0;
void registerTypes(const char *uri) override;
void unregisterTypes() override;