aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2021-03-18 16:04:41 +0100
committerMitch Curtis <mitch.curtis@qt.io>2021-03-24 09:20:59 +0100
commit23cad8990c5df9a65ceccb1db7f023561753ec0b (patch)
tree3f31b452b4f72df4907816a3cc041875c9a7d846 /examples
parentafc40d87e11d1da3d2cd9a59fb5dd24a29026373 (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++. Pick-to: 6.1 6.0 Change-Id: Ia8654f28ae6adc9171d667c2c5c3603a15251cab Fixes: QTBUG-91989 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'examples')
-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)