![]() |
Home · All Classes · All Functions · Overviews |
[Inherits Item]
The Repeater item allows you to repeat a component based on a model. More...
The Repeater item is used when you want to create a large number of similar items. For each entry in the model, an item is instantiated in a context seeded with data from the model. If the repeater will be instantiating a large number of instances, it may be more efficient to use one of Qt Declarative's view items.
The model may be either an object list, a string list, a number or a Qt model. In each case, the data element and the index is exposed to each instantiated component.
The index is always exposed as an accessible index property. In the case of an object or string list, the data element (of type string or object) is available as the modelData property. In the case of a Qt model, all roles are available as named properties just like in the view classes. The following example shows how to use the index property inside the instantiated items.
Column { Repeater { model: 10 Text { text: "I'm item " + index } } }
Items instantiated by the Repeater are inserted, in order, as children of the Repeater's parent. The insertion starts immediately after the repeater's position in its parent stacking list. This is to allow you to use a Repeater inside a layout. The following QML example shows how the instantiated items would visually appear stacked between the red and blue rectangles.
Row { Rectangle { width: 10; height: 20; color: "red" } Repeater { model: 10 Rectangle { width: 20; height: 20; radius: 10; color: "green" } } Rectangle { width: 10; height: 20; color: "blue" } }
The repeater instance continues to own all items it instantiates, even if they are otherwise manipulated. It is illegal to manually remove an item created by the Repeater.
read-onlycount : int |
This property holds the number of items in the repeater.
delegate : Component |
default |
The delegate provides a template defining each item instantiated by the repeater. The index is exposed as an accessible index property. Properties of the model are also available depending upon the type of Data Model.
The model providing data for the repeater.
The model may be either an object list, a string list, a number or a Qt model. In each case, the data element and the index is exposed to each instantiated component. The index is always exposed as an accessible index property. In the case of an object or string list, the data element (of type string or object) is available as the modelData property. In the case of a Qt model, all roles are available as named properties just like in the view classes.
As a special case the model can also be merely a number. In this case it will create that many instances of the component. They will also be assigned an index based on the order they are created.
Models can also be created directly in QML, using a ListModel or XmlListModel.
See also Data Models.
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.7.0 |