Loading multiple QML files via single button (click by click)
-
Hi all,
I have a column with some loaders inside and would like to call these files via "myButton", but one by one instead of a single shot. Is it possible to add this condition to myButton so it can differentiate or ordinate every click? Thanks.main.qml:
Item { myButton { onClicked: loader.source = "MyWidget.qml" } Loader { id: loader1 anchors.fill: parent } }
-
Button{
property int i: 0 property int n: 3 //number of QML files for load onClicked: { if(i === 0) loader.source = "MyWidget.qml" if(i === 1) loader.source = "MyWidget1.qml" if(i === 2) loader.source = "MyWidget2.qml" ... if(i === n) loader.source = "MyWidgetn.qml" i = (i == n ? 0 : ++i) }
}
-
@qtprogrammer123 Thank you so much!
-
This post is deleted!
-
@qtprogrammer123 do you have idea on how to do the way back? I mean unload them one by one? Thanks. Couldn't find anything about.
These lines below can't work properly as the 3 loaders are inactive by the "removeButton" I'm not able to lead them again.
MyRemoveButton { ... property int i: 0 property int n: 3 //number of QML files for load onClicked: { if(i === 0) loader3.active = false if(i === 1) loader2.active = false if(i === 2) loader1.active = false i = (i == n ? 0 : ++i) } } }
-
@qtprogrammer123 Thank you.
The loading and unloading process is working fine but after unloading the last source nothing happens. There should be a way to make this reusable. Would you know how to fix this?