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 에 세 개의 색상이 있는 직사각형을 배치합니다.
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]
모델의 항목 수입니다. 이 속성은 읽기 전용입니다.
첨부된 속성 문서
ObjectModel.index : int
이 첨부 프로퍼티는 모델 내에서 이 델리게이트 항목의 인덱스를 보유합니다.
델리게이트의 각 인스턴스에 첨부됩니다.
메서드 문서
void append(object item)
모델 끝에 item 을 새로 추가합니다.
objectModel.append(objectComponent.createObject())
void clear()
모델에서 모든 항목을 지웁니다.
object get(int index)
모델의 index 에서 항목을 반환합니다. 이렇게 하면 자바스크립트에서 항목에 액세스하거나 수정할 수 있습니다:
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 은 목록의 기존 항목에 있거나 목록의 끝에 있는 항목(추가에 해당)이어야 합니다.
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.