ObjectModel QML Type
モデルとして使用するアイテムのセットを定義します。詳細...
Import Statement: | import QtQml.Models |
プロパティ
- count : int
付属物件
- index : int
方法
- append(object item)
- clear()
- object get(int index)
- insert(int index, object item)
- move(int from, int to, int n)
- remove(int index, int n)
詳細説明
ObjectModel にはビューで使用されるビジュアルアイテムが含まれています。ObjectModel がビューで使用される場合、ObjectModel には既にビジュアルデリゲート(アイテム)が含まれているため、ビューはデリゲートを必要としません。
アイテムは、index のアタッチプロパティにより、モデル内のインデックスを決定することができます。
以下の例では、ListView に 3 つの色の付いた長方形を配置しています。
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 } }
Qt Quick 例 - ビューも参照してください 。
プロパティの説明
count : int |
モデル内のアイテムの数。このプロパティは読み取り専用です。
Attached Property ドキュメント
ObjectModel.index : int |
この Attached プロパティは、モデル内のこのデリゲートのアイテムのインデックスを保持します。
このプロパティは、デリゲートの各インスタンスにアタッチされます。
メソッドの説明
append(object item) |
object get(int index) |
モデル内のindex にある項目を返します。これにより、JavaScript からアイテムにアクセスしたり、アイテムを変更したりすることができます:
Component.onCompleted: { objectModel.append(objectComponent.createObject()) console.log(objectModel.get(0).objectName); objectModel.get(0).objectName = "first"; }
index はリストの要素でなければなりません。
append()も参照してください 。
insert(int index, object item) |
n 項目from をある位置to に移動する。
fromとtoの範囲が存在する必要があります。例えば、最初の3つの項目をモデルの最後に移動する場合です:
objectModel.move(0, objectModel.count - 3, 3)
append()も参照 。
© 2025 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.