Package QML Type
Especifica una colección de elementos con nombre. Más...
| Import Statement: | import QtQml.Models |
Propiedades asociadas
- name : string
Descripción detallada
El tipo «Package» se utiliza junto con la propiedad adjunta « DelegateModel » para permitir que se proporcionen delegados con un contexto compartido a varias vistas.
A cualquier elemento dentro de un «Package» se le puede asignar un nombre mediante la propiedad adjunta « Package.name ».
El ejemplo siguiente crea un «Package» que contiene dos elementos con nombre: «list » y «grid». El tercer elemento del «Package» (el « Rectangle ») se vincula al delegado en el que deba aparecer. Esto permite que un elemento se desplace entre vistas.
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 }
}
}
]
}
}Estos elementos con nombre se utilizan como delegados por las dos vistas, que hacen referencia a la propiedad especial « DelegateModel::parts » para seleccionar un modelo que proporcione el delegado elegido.
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
}Nota: «Package» forma parte de « QtQml.Models » desde la versión 2.14 y de « QtQuick » desde la versión 2.0. La importación de «Package» a través de « QtQuick » está obsoleta desde Qt 5.14.
Véase también Ejemplos deQt Quick: Vistas y Qt Qml.
Documentación de la propiedad adjunta
Package.name : string [attached]
Esta propiedad asociada contiene el nombre de un elemento dentro de un paquete.
© 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.