Package QML Type
名前付き項目のコレクションを指定します。詳細...
| Import Statement: | import QtQml.Models |
関連プロパティ
- name : string
詳細な説明
Package 型は、DelegateModel と組み合わせて使用され、共有コンテキストを持つデリゲートを複数のビューに提供できるようにします。
パッケージ内の任意のアイテムには、Package.name 添付プロパティを介して名前を割り当てることができます。
以下の例では、listとgrid という 2 つの名前付きアイテムを含むパッケージを作成しています。パッケージ内の 3 番目のアイテム(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 }
}
}
]
}
}これらの名前付きアイテムは、2つのビューによってデリゲートとして使用され、各ビューは特別な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.