How I can to load to the AppListView SimpleRow with AppSwitch or AppButon, dependent of values of array?
-
In ‘AppListView’ are empty places where Loader should load Component with ‘SimpleRow’
I have a code application written in QT/QML and V-PLAY on the github here:
https://github.com/pyroxar/VplayfirstApp
My problem:I want to use AppListView to display different elements (like Button or SwitchApp) in ‘Ustawienia’ (Settings) page dependent on elements in array:
property var typeOfElementsInSettings: [‘switch’,’switch’,’button’,’switch’]
I use ‘delegete: Loader’ to do It, I inspired in this thread.
https://stackoverflow.com/questions/31985972/different-delegates-for-qml-listview
I load component from other file, one will have Button inside, other AppSwitcher. Loader inserts SimpleRow to AppListView, I know It because variable myIndex should increment when SimpleRow is added and It was incremented but I can’t see anything. I mean that I see empty space in place where should be displayed SimpleRow.See screenshot:
https://screenshots.firefox.com/BgiM3n0sZd7Vt6p3/stackoverflow.com
How I can to load to the AppListView SimpleRow with AppSwitch or AppButon, dependent of values of array?property var typeOfElementsInSettings: ['switch','switch','button','switch','button','switch','switch','switch']
How i Can do It? I don’t have any idea, please give me the tip.
My code SimpleRowButton.qml:import VPlayApps 1.0 import QtQuick 2.9 Component{ SimpleRow { text: "name"; AppButton{ text: "aaaa" anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right anchors.rightMargin: dp(10) Component.onCompleted: { console.log(myIndex) console.log("Przycisk") //myIndex++; } } Component.onCompleted: { console.log("bbb"+switchsSettingsLogicArray[myIndex]) //console.log(myIndex) myIndex++ } } }
SimpleRowSwitch.qml:
import VPlayApps 1.0 import QtQuick 2.9 Component{ SimpleRow { text: "name"; AppSwitch{ anchors.verticalCenter: parent.verticalCenter anchors.right: parent.right anchors.rightMargin: dp(10) Component.onCompleted: { console.log(myIndex) if(switchsSettingsLogicArray[myIndex]===1){ checked=true } else { checked=false } //myIndex++; } onToggled: { console.log(myIndex) } } Component.onCompleted: { console.log("a"+switchsSettingsLogicArray[myIndex]) //console.log(myIndex) myIndex++ } } }
Main.qml (all):
import VPlayApps 1.0 import QtQuick 2.9 App { //var appswitchs = {id: 1, value: false; id: 2, value: false}; id: app property var switchsSettingsLogicArray: [0,0,1,1,1,0,0,1,1] property var typeOfElementsInSettings: ['switch','switch','button','switch','button','switch','switch','switch'] property var firstRun property int myIndex: 0 Navigation{ NavigationItem{ title: "Listy" icon: IconType.checkcircle NavigationStack{ Page{ id: task1 navigationBarTranslucency: 0.0 title: "Listy" SearchBar { id: searchBarThreads onAccepted: { } } } } } NavigationItem{ title: "Konto użytkownika" icon: IconType.user NavigationStack{ Page{ title: "Konto użytkownia" } } } NavigationItem{ title: "Ustawienia" icon: IconType.cogs NavigationStack{ Page{ title: "Ustawienia" AppListView{ model: ListModel{ ListElement{ type: "kategoria 1"; name: "opcja 1" } ListElement{ type: "kategoria 12"; name: "opcja 2" } ListElement{ type: "kategoria 23"; name: "opcja 3" } ListElement{ type: "Opcje programisty"; name: "Czyszczenie ustawień aplikacji" } ListElement{ type: "kategoria 11"; name: "opcja 1" } ListElement{ type: "kategoria 1"; name: "opcja 2" } ListElement{ type: "kategoria 2"; name: "opcja 3" } ListElement{ type: "Opcje programisty2"; name: "Czyszczenie ustawień aplikacji" } } //Error here section.property: "type"; section.delegate: SimpleRow { title: section } delegate: Loader{ //asynchronous: true //visible: status == Loader.Ready sourceComponent: { switch(typeOfElementsInSettings[myIndex]){ case "switch": console.log("switch") return SimpleRowButton.qml; case "button": console.log("button") return SimpleRowButton.qml; } } } } } } onSelected: { //console.log("selected") } Component.onCompleted: { //console.log("Zrobiono") } } } function init(){ console.log("initialization...") } Component.onCompleted: { app.settings.clearAll() if(app.settings.getValue("firstRun") === undefined){ console.log("firstRun: false") init() app.settings.setValue("firstRun", false) } } }
AppListView is ListView from pure qml.
-
Hi,
Since you are using V-Play, you might want to bring that question to their forum.