aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2021-03-18 16:04:41 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-03-25 09:21:28 +0000
commit6495c0da733cc16f07d0aa6db03ddadd646d3ee9 (patch)
treeac39ec1b650979a327f5cb5ac25c1711111a4d11
parent4ecbdcad8e381e559420ed6b96527223baacebb3 (diff)
Fix gallery example defaulting to Basic instead of the platform default
The example used to default to the Default style, and when that was renamed to Basic and the default style behavior changed, we forgot to adapt the style property in the QML Settings instance. We should now not set any value as a default, and instead ensure that the style is set on the QSettings in C++. Change-Id: Ia8654f28ae6adc9171d667c2c5c3603a15251cab Fixes: QTBUG-91989 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 23cad8990c5df9a65ceccb1db7f023561753ec0b) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--examples/quickcontrols2/gallery/gallery.cpp11
-rw-r--r--examples/quickcontrols2/gallery/gallery.qml6
2 files changed, 13 insertions, 4 deletions
diff --git a/examples/quickcontrols2/gallery/gallery.cpp b/examples/quickcontrols2/gallery/gallery.cpp
index 82706d53..1ea5cf98 100644
--- a/examples/quickcontrols2/gallery/gallery.cpp
+++ b/examples/quickcontrols2/gallery/gallery.cpp
@@ -65,9 +65,16 @@ int main(int argc, char *argv[])
QIcon::setThemeName("gallery");
QSettings settings;
- if (qgetenv("QT_QUICK_CONTROLS_STYLE").isEmpty())
+ if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
QQuickStyle::setStyle(settings.value("style").toString());
+ // If this is the first time we're running the application,
+ // we need to set a style in the settings so that the QML
+ // can find it in the list of built-in styles.
+ const QString styleInSettings = settings.value("style").toString();
+ if (styleInSettings.isEmpty())
+ settings.setValue(QLatin1String("style"), QQuickStyle::name());
+
QQmlApplicationEngine engine;
QStringList builtInStyles = { QLatin1String("Basic"), QLatin1String("Fusion"),
@@ -77,8 +84,8 @@ int main(int argc, char *argv[])
#elif defined(Q_OS_WINDOWS)
builtInStyles << QLatin1String("Windows");
#endif
- engine.rootContext()->setContextProperty("builtInStyles", builtInStyles);
+ engine.setInitialProperties({{ "builtInStyles", builtInStyles }});
engine.load(QUrl("qrc:/gallery.qml"));
if (engine.rootObjects().isEmpty())
return -1;
diff --git a/examples/quickcontrols2/gallery/gallery.qml b/examples/quickcontrols2/gallery/gallery.qml
index 8a074254..58d1b49e 100644
--- a/examples/quickcontrols2/gallery/gallery.qml
+++ b/examples/quickcontrols2/gallery/gallery.qml
@@ -73,9 +73,11 @@ ApplicationWindow {
Qt.openUrlExternally(url)
}
+ required property var builtInStyles
+
Settings {
id: settings
- property string style: "Basic"
+ property string style
}
Shortcut {
@@ -285,7 +287,7 @@ ApplicationWindow {
ComboBox {
id: styleBox
property int styleIndex: -1
- model: builtInStyles
+ model: window.builtInStyles
Component.onCompleted: {
styleIndex = find(settings.style, Qt.MatchFixedString)
if (styleIndex !== -1)