Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qml Repeater with ids

Tags:

qt

qml

If wrote the following code:

Repeater { model: 10; 
delegate: Rectangle { width: 200; height:           
20; color: "white";}}

How can I give all the 10 rectangles a different id?

like image 229
John Smith Avatar asked Mar 22 '19 23:03

John Smith


1 Answers

You can not assign a different id, also the id has a scope whose limit is the delegate, if you want to access an item you must use the itemAt() method passing the index:

Repeater { 
    id: repeater
    model: 10; 
    delegate: Rectangle { 
        width: 200; 
        height: 20; 
        color: "white";
    }
}

// ...

var item = repeater.itemAt(2)
like image 81
eyllanesc Avatar answered Nov 15 '22 06:11

eyllanesc