Package QML Type
이름이 지정된 항목들의 모음을 지정합니다. 더 보기...
| Import Statement: | import QtQml.Models |
부속 속성
- name : string
상세 설명
Package 유형은 DelegateModel 와 함께 사용되어, 공유된 컨텍스트를 가진 델리게이트를 여러 뷰에 제공할 수 있도록 합니다.
패키지 내의 모든 항목에는 ' Package.name ' 부가 속성을 통해 이름을 지정할 수 있습니다.
아래 예제는 list와 grid라는 두 개의 이름이 지정된 항목을 포함하는 Package를 생성합니다. 패키지의 세 번째 항목( Rectangle)은 표시되어야 할 델리게이트에 종속됩니다. 이를 통해 항목이 뷰 간에 이동할 수 있습니다.
Package {
Text { id: listDelegate; width: parent.width; height: 25; text: 'Empty'; Package.name: 'list' }
Text { id: gridDelegate; width: parent.width / 2; height: 50; text: 'Empty'; Package.name: 'grid' }
Rectangle {
id: wrapper
width: parent.width; height: 25
color: 'lightsteelblue'
Text { text: display; anchors.centerIn: parent }
state: root.upTo > index ? 'inGrid' : 'inList'
states: [
State {
name: 'inList'
ParentChange { target: wrapper; parent: listDelegate }
},
State {
name: 'inGrid'
ParentChange {
target: wrapper; parent: gridDelegate
x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height
}
}
]
transitions: [
Transition {
ParentAnimation {
NumberAnimation { properties: 'x,y,width,height'; duration: 300 }
}
}
]
}
}이 이름이 지정된 항목들은 두 뷰에서 델리게이트로 사용되며, 해당 뷰들은 특수한 ` DelegateModel::parts ` 속성을 참조하여 선택된 델리게이트를 제공하는 모델을 선택합니다.
DelegateModel {
id: visualModel
delegate: Delegate {}
model: myModel
}
ListView {
id: lv
height: parent.height/2
width: parent.width
model: visualModel.parts.list
}
GridView {
y: parent.height/2
height: parent.height/2
width: parent.width
cellWidth: width / 2
cellHeight: 50
model: visualModel.parts.grid
}참고: Package는 버전 2.14부터 QtQml.Models 의 일부이며, 버전 2.0부터 QtQuick 의 일부입니다. QtQuick 를 통해 Package를 임포트하는 방법은 Qt 5.14부터 더 이상 권장되지 않습니다.
참조: Qt Quick 예제 - 뷰 및 Qt Qml.
부착 속성 문서
Package.name : string [attached]
이 첨부 속성은 패키지 내 항목의 이름을 저장합니다.
© 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.