Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

ListElement QML Element

TheListElement element defines a data item in aListModel.More...

Since: Qt 4.7

Detailed Description

List elements are defined insideListModel definitions, and represent items in a list that will be displayed usingListView orRepeater items.

List elements are defined like other QML elements except that they contain a collection ofrole 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 toQT_TR_NOOP), boolean values (true, false), numbers, or enumeration values (such as AlignText.AlignHCenter).

Referencing Roles

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 themodel property (e.g.,model.cost instead ofcost).

Example Usage

The following model defines a series of list elements, each of which contain "name" and "cost" roles and their associated values.

ListModel {id:fruitModelListElement {name:"Apple"cost:2.45    }ListElement {name:"Orange"cost:3.25    }ListElement {name:"Banana"cost:1.95    }}

The delegate obtains the name and cost for each element by simply referring toname andcost:

ListView {anchors.fill:parentmodel:fruitModeldelegate:Row {Text {text:"Fruit: "+name }Text {text:"Cost: $"+cost }    }}

See alsoListModel.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp