ObjectModel QML Type

모델로 사용할 항목 집합을 정의합니다. 자세히...

Import Statement: import QtQml.Models

속성

첨부 속성

방법

자세한 설명

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

이 첨부 속성은 모델 내에서 이 델리게이트 항목의 인덱스를 보유합니다.

델리게이트의 각 인스턴스에 첨부됩니다.


메서드 문서

append(object item)

모델 끝에 새 item 을 추가합니다.

objectModel.append(objectComponent.createObject())

insert() 및 remove()도 참조하세요 .


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()도 참조하세요 .


insert(int index, object item)

index 위치에 모델에 새 item 을 삽입합니다.

objectModel.insert(2, objectComponent.createObject())

index 은 목록의 기존 항목에 있거나 목록의 끝에 있는 항목(추가와 동일)이어야 합니다.

append() 및 remove()도 참조하세요 .


move(int from, int to, int n = 1)

n 항목을 from 한 위치 to 다른 위치로 이동합니다.

예를 들어 처음 3개 항목을 모델의 끝으로 이동하려면 from 및 to 범위가 존재해야 합니다:

objectModel.move(0, objectModel.count - 3, 3)

append()도 참조하세요 .


remove(int index, int n = 1)

모델에서 indexn 항목을 제거합니다.

clear()도 참조하세요 .


© 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.