ObjectModel QML Type
Defines a set of items to be used as a model More...
Import Statement: | import QtQml.Models 2.2 |
Properties
- count : int
Attached Properties
- index : int
Methods
- void append(object item)
- void clear()
- object get(int index)
- void insert(int index, object item)
- void move(int from, int to, int n)
- void remove(int index, int n)
Detailed Description
A ObjectModel contains the visual items to be used in a view. When a ObjectModel is used in a view, the view does not require a delegate since the ObjectModel already contains the visual delegate (items).
An item can determine its index within the model via the index attached property.
The example below places three colored rectangles in a ListView.
import QtQuick 2.0 import QtQml.Models 2.1 Rectangle { ObjectModel { id: itemModel Rectangle { height: 30; width: 80; color: "red" } Rectangle { height: 30; width: 80; color: "green" } Rectangle { height: 30; width: 80; color: "blue" } } ListView { anchors.fill: parent model: itemModel } }
See also Qt Quick Examples - Views.
Property Documentation
Attached Property Documentation
This attached property holds the index of this delegate's item within the model.
It is attached to each instance of the delegate.
Method Documentation
Returns the item at index in the model. This allows the item to be accessed or modified from JavaScript:
Component.onCompleted: { objectModel.append(objectComponent.createObject()) console.log(objectModel.get(0).objectName); objectModel.get(0).objectName = "first"; }
The index must be an element in the list.
This QML method was introduced in Qt 5.6.
See also append().
Moves n items from one position to another.
The from and to ranges must exist; for example, to move the first 3 items to the end of the model:
objectModel.move(0, objectModel.count - 3, 3)
This QML method was introduced in Qt 5.6.
See also append().
Removes the items at index from the model.
This QML method was introduced in Qt 5.6.
See also clear().
© 2017 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 the GNU 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.