ObjectModel QML Type
モデルとして使用するアイテムのセットを定義します。詳細...
| Import Statement: | import QtQml.Models |
プロパティ
- count : int
付属物件
- index : int
方法
- 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)
詳細説明
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 [read-only]
モデル内のアイテムの数。このプロパティは読み取り専用です。
Attached Property ドキュメント
ObjectModel.index : int
このアタッチされたプロパティは、モデル内のこのデリゲートのアイテムのインデックスを保持します。
これは、デリゲートの各インスタンスにアタッチされます。
メソッドのドキュメント
void append(object item)
モデルの最後に新しいitem を追加する。
objectModel.append(objectComponent.createObject())
void clear()
モデルからすべての項目を消去する。
append() およびremove()も参照してください 。
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()も参照してください 。
void insert(int index, object item)
index の位置に新しいitem をモデルに挿入する。
objectModel.insert(2, objectComponent.createObject())
index は、リスト内の既存の項目か、リストの末尾からひとつ過ぎた項目でなければなりません(append と同じです)。
void move(int from, int to, int n = 1)
n 項目from をある位置to に移動する。
例えば、最初の3つの項目をモデルの最後に移動させる場合です:
objectModel.move(0, objectModel.count - 3, 3)
append()も参照してください 。
void remove(int index, int n = 1)
index のn の項目をモデルから削除する。
clear()も参照してください 。
© 2026 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.