TableModelColumn QML Type
Representa una columna en un modelo. Más...
| Import Statement: | import Qt.labs.qmlmodels |
Descripción detallada
La clase `TableModelColumn` representa las columnas de un ` TableModel`. ` TableModel ` admite datos JavaScript/JSON en los que cada fila es un objeto, es decir, una lista de pares clave-valor simples en la que las claves no están ordenadas.
{
// Each property is one cell/column.
checked: false,
amount: 1,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
// ...Sin embargo, los modelos en Qt se manipulan mediante índices de fila y columna. Especificar las columnas con TableModelColumn permite establecer una correspondencia entre los roles integrados de Qt y cualquier propiedad de cada objeto de fila.
import QtQuick
import QtQuick.Window
import Qt.labs.qmlmodels
Window {
width: 400
height: 400
visible: true
TableView {
anchors.fill: parent
columnSpacing: 1
rowSpacing: 1
boundsBehavior: Flickable.StopAtBounds
model: TableModel {
TableModelColumn { display: "checked" }
TableModelColumn { display: "amount" }
TableModelColumn { display: "fruitType" }
TableModelColumn { display: "fruitName" }
TableModelColumn { display: "fruitPrice" }
// Each row is one type of fruit that can be ordered
rows: [
{
// Each property is one cell/column.
checked: false,
amount: 1,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: true,
amount: 4,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: false,
amount: 1,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
}
]
}
delegate: TextInput {
text: model.display
padding: 12
selectByMouse: true
onAccepted: model.display = text
Rectangle {
anchors.fill: parent
color: "#efefef"
z: -1
}
}
}
}TableModelColumn también ofrece compatibilidad básica de solo lectura para filas complejas. Para obtener más información, consulta Supported Row Data Structures.
Nota: La mayoría de los conceptos anteriores también se aplican a TreeModel, salvo que en TreeModel cada fila representa un nodo del árbol.
Roles compatibles
TableModelColumn admite todas las funciones de Qt's roles, a excepción de Qt::InitialSortOrderRole. Se puede acceder a las funciones tal y como se indica a continuación, p. ej.:
text: display
required property string display| Qt::DisplayRole | display |
| Qt::DecorationRole | decoration |
| Qt::EditRole | edit |
| Qt::ToolTipRole | toolTip |
| Qt::StatusTipRole | statusTip |
| Qt::WhatsThisRole | ¿qué es esto? |
| Qt::FontRole | fuente |
| Qt::TextAlignmentRole | textAlignment |
| Qt::BackgroundRole | fondo |
| Qt::ForegroundRole | primer plano |
| Qt::CheckStateRole | estado de selección |
| Qt::AccessibleTextRole | texto accesible |
| Qt::AccessibleDescriptionRole | descripción accesible |
| Qt::SizeHintRole | sugerencia de tamaño del nombre de función |
Véase también TableModel y TableView.
© 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.