이 페이지에서

ObjectModel QML Type

모델로 사용할 항목 집합을 정의합니다. 더 보기...

Import Statement: import QtQml.Models

속성

연관 속성

방법

  • void append(object item)
  • void clear()
  • QtObject 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
    }
}

ListView에 세 개의 색깔이 다른 직사각형을 겹쳐서 배치하기

'Qt Quick ' 예제 - 뷰도 참조하십시오 .

속성 설명서

count : int [read-only]

모델에 포함된 항목의 수입니다. 이 속성은 읽기 전용입니다.

부속 속성 설명서

ObjectModel.index : int [attached]

이 부가 속성은 모델 내에서 이 델리게이트의 항목이 차지하는 인덱스를 저장합니다.

이 속성은 각 델리게이트 인스턴스에 연결되어 있습니다.

메서드 문서

void append(object item)

모델의 끝에 새로운 ` item `를 추가합니다.

objectModel.append(objectComponent.createObject())

insert() 및 remove()도 참조하십시오 .

void clear()

모델에서 모든 항목을 지웁니다.

append() 및 remove()도 참조하십시오 .

QtObject 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와 동일).

append() 및 remove()도 참조하십시오 .

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

n 항목들을 from 한 칸씩 이동시키고 to 또 다른 칸으로 이동시킵니다.

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.