Search code examples
qtqml

Repeater items with different ids


Consider the following:

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

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


Solution

  • 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)