[SOLVED] Iteration of QML elements
-
Hi everyone.
How can I iterate a part of qml code with a help of js or c++ maybe.
That,s what I want to do -@
for(i=0;i<10;i++){/->code to iterate/
Rectangle{
width: 59
height: 80
border.color: "#000"
Image {
fillMode: Image.PreserveAspectFit
source: i+".png"
}
MouseArea{
anchors.fill:parent
onEntered:parent.border.color = "#ffffff"
onExited:parent.border.color = "#000000"
onClicked:{
if(parent.opacity == 1)parent.opacity = 0.5
else parent.opacity = 1
onClicked:LibJs.updateDeckMemResults(i)
}
}
}
/<-code to iterate/}
@
I thought about creating objects from .qml file in a cycle in js but in this case I can,t use LibJs object because of variables in js will be redifined each time I call LibJs.updateDeckMemResults(i). Google didn
t help, but may be I didn
t asked right question... -
Hello,
If I understand you right, you want to create 10 Rectangles. You could use "Repeater":http://doc.qt.nokia.com/4.7-snapshot/qml-repeater.html and it`s property index
-
You basically want to dynamically generate 10 instances of a Component (the Rectangle).
You should split it out into a separate .qml file (eg, MyRect.qml), and then you can use Qt.createComponent() and Qt.createObject() to construct instances dynamically.Alternatively, you could use a Repeater or something (http://doc.qt.nokia.com/5.0-snapshot/qml-qtquick2-repeater.html).