Qt 4.8
|
The ListElement element defines a data item in a ListModel. More...
The ListElement element defines a data item in a ListModel.
List elements are defined inside ListModel definitions, and represent items in a list that will be displayed using ListView or Repeater items.
List elements are defined like other QML elements except that they contain a collection of role definitions instead of properties. Using the same syntax as property definitions, roles both define how the data is accessed and include the data itself.
The names used for roles must begin with a lower-case letter and should be common to all elements in a given model. Values must be simple constants; either strings (quoted and optionally within a call to QT_TR_NOOP), boolean values (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter).
The role names are used by delegates to obtain data from list elements. Each role name is accessible in the delegate's scope, and refers to the corresponding role in the current element. Where a role name would be ambiguous to use, it can be accessed via the ListView::model property (e.g., model.cost
instead of cost
).
The following model defines a series of list elements, each of which contain "name" and "cost" roles and their associated values.
The delegate obtains the name and cost for each element by simply referring to name
and cost: