Qt 4.8
Repeater Class Reference

The Repeater element allows you to repeat an Item-based component using a model. More...

Inheritance diagram for Repeater:
Item

Detailed Description

The Repeater element allows you to repeat an Item-based component using a model.

Since
4.7
The Repeater element is used to create a large number of
similar items. Like other view elements, a Repeater has a \link model \endlink  and a \link delegate \endlink :
for each entry in the model, the delegate is instantiated
in a context seeded with data from the model. A Repeater item is usually
enclosed in a positioner element such as \link Row \endlink  or \link Column \endlink  to visually
position the multiple delegate items created by the Repeater.

The following Repeater creates three instances of a \link Rectangle \endlink  item within
a \link Row \endlink :

\snippet doc/src/snippets/declarative/repeaters/repeater.qml import

\snippet doc/src/snippets/declarative/repeaters/repeater.qml simple

\image html repeater-simple.png

A Repeater's \link model \endlink  can be any of the supported \link qmlmodels \endlink{data models}.
Additionally, like delegates for other views, a Repeater delegate can access
its index within the repeater, as well as the model data relevant to the
delegate. See the \link delegate \endlink  property documentation for details.

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 allows
a Repeater to be used inside a layout. For example, the following Repeater's
items are stacked between a red rectangle and a blue rectangle:

\snippet doc/src/snippets/declarative/repeaters/repeater.qml layout

\image html repeater.png


\note A Repeater item owns all items it instantiates. Removing or dynamically destroying
an item created by a Repeater results in unpredictable behavior.

Considerations when using Repeater

The Repeater element creates all of its delegate items when the repeater is first created. This can be inefficient if there are a large number of delegate items and not all of the items are required to be visible at the same time. If this is the case, consider using other view elements like ListView (which only creates delegate items when they are scrolled into view) or use the Dynamic Object Creation methods to create items as they are required.

Also, note that Repeater is Item-based, and can only repeat Item-derived objects. For example, it cannot be used to repeat QtObjects: Item { XXX does not work! Can't repeat QtObject as it doesn't derive from Item. Repeater { model: 10 QtObject {} } }


The documentation for this class was generated from the following file: