aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-05-18 14:54:33 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-05-19 11:46:37 +0200
commit3168111285601de30a24455282ed6450cd1a5799 (patch)
treef59f219f5c53b3993ab765a051a986508d572d8d /examples/qml
parent94f34ef69bda1378471c0e39bd354b99179dbb0d (diff)
examples/qml/locale: Use inline component as a delegate
Modernize the code by using an inline component as a delegate in this example file instead of declaring the delegate inline. Change-Id: I52c75f81c42362f858f63bdbbaf432c0966309fe Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'examples/qml')
-rw-r--r--examples/qml/locale/locale.qml28
1 files changed, 17 insertions, 11 deletions
diff --git a/examples/qml/locale/locale.qml b/examples/qml/locale/locale.qml
index e48c86deb8..4b7fc0506c 100644
--- a/examples/qml/locale/locale.qml
+++ b/examples/qml/locale/locale.qml
@@ -56,7 +56,21 @@ Rectangle {
height: 480
color: "lightgray"
- property string locale: view.currentItem.locale
+ component LocaleDelegate: Text {
+ required property var modelData
+ required property int index
+
+ property string locale: modelData
+ height: 30
+ width: view.width
+ text: `${Qt.locale(modelData).name} (${Qt.locale(modelData).nativeCountryName}/${Qt.locale(modelData).nativeLanguageName})`
+ MouseArea {
+ anchors.fill: parent
+ onClicked: view.currentIndex = parent.index
+ }
+ }
+
+ property string locale: (view.currentItem as LocaleDelegate).locale
Text {
id: title
@@ -89,16 +103,8 @@ Rectangle {
"nb_NO",
"sv_SE"
]
- delegate: Text {
- property string locale: modelData
- height: 30
- width: view.width
- text: Qt.locale(modelData).name + " ("+ Qt.locale(modelData).nativeCountryName + "/" + Qt.locale(modelData).nativeLanguageName + ")"
- MouseArea {
- anchors.fill: parent
- onClicked: view.currentIndex = index
- }
- }
+
+ delegate: LocaleDelegate {}
highlight: Rectangle {
height: 30
color: "#60300030"