[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 -


    /->code to iterate/
    width: 59
    height: 80
    border.color: "#000"
    Image {
    fillMode: Image.PreserveAspectFit
    source: i+".png"
    onEntered:parent.border.color = "#ffffff"
    onExited:parent.border.color = "#000000"
    if(parent.opacity == 1)parent.opacity = 0.5
    else parent.opacity = 1
    /<-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 didnt help, but may be I didnt 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).

  • task_struct

    Thank you very much - this is perfect solution in my case.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.