Package QML Type
Spécifie une collection d'éléments nommés. Plus d'informations...
| Import Statement: | import QtQml.Models |
Propriétés attachées
- name : string
Description détaillée
Le type Package est utilisé en conjonction avec DelegateModel pour permettre aux délégués ayant un contexte partagé d'être fournis à plusieurs vues.
Tout élément d'un Package peut se voir attribuer un nom via la propriété attachée Package.name.
L'exemple ci-dessous crée un package contenant deux éléments nommés : list et grid. Le troisième élément du paquet ( Rectangle) est rattaché au délégué dans lequel il doit apparaître. Cela permet à un élément de se déplacer d'une vue à l'autre.
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 } } } ] } }
Ces éléments nommés sont utilisés comme délégués par les deux vues qui font référence à la propriété spéciale DelegateModel::parts pour sélectionner un modèle qui fournit le délégué choisi.
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 }
Remarque : Package fait partie de QtQml.Models depuis la version 2.14 et de QtQuick depuis la version 2.0. L'importation de Package via QtQuick est obsolète depuis la version 5.14 de Qt.
Voir aussi Qt Quick Exemples - Vues et Qt Qml.
Documentation sur les propriétés attachées
Package.name : string
Cette propriété jointe contient le nom d'un élément au sein d'un paquet.
© 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.