TableModelColumn QML Type
Stellt eine Spalte in einem Modell dar. Mehr...
| Import Statement: | import Qt.labs.qmlmodels |
Ausführliche Beschreibung
Die Klasse `TableModelColumn` repräsentiert Spalten in ` TableModel`. ` TableModel ` unterstützt JavaScript-/JSON-Daten, bei denen jede Zeile ein Objekt ist – eine Liste einfacher Schlüssel-Wert-Paare, deren Schlüssel ungeordnet sind.
{
// Each property is one cell/column.
checked: false,
amount: 1,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
// ...Modelle in Qt werden jedoch über Zeilen- und Spaltenindizes manipuliert. Die Angabe der Spalten mit `TableModelColumn` ermöglicht eine Zuordnung zwischen den in Qt integrierten Rollen und beliebigen Eigenschaften in jedem Zeilenobjekt.
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“ bietet zudem eine grundlegende Lesezugriffsunterstützung für komplexe Zeilen. Weitere Informationen finden Sie unter Supported Row Data Structures.
Hinweis: Die meisten der oben genannten Konzepte gelten auch für TreeModel, mit der Ausnahme, dass bei TreeModel jede Zeile einen Knoten des Baums darstellt.
Unterstützte Rollen
TableModelColumn unterstützt alle Funktionen von Qt's roles, mit Ausnahme von Qt::InitialSortOrderRole. Der Zugriff auf die Rollen erfolgt wie unten aufgeführt, z. B.
text: display
required property string display| Qt::DisplayRole | display |
| Qt::DecorationRole | decoration |
| Qt::EditRole | edit |
| Qt::ToolTipRole | ToolTip |
| Qt::StatusTipRole | statusTip |
| Qt::WhatsThisRole | Was ist das? |
| Qt::FontRole | Schriftart |
| Qt::TextAlignmentRole | textAlignment |
| Qt::BackgroundRole | Hintergrund |
| Qt::ForegroundRole | Vordergrund |
| Qt::CheckStateRole | Check-Zustand |
| Qt::AccessibleTextRole | barrierefreier Text |
| Qt::AccessibleDescriptionRole | barrierefreie Beschreibung |
| Qt::SizeHintRole | GrößenhinweisRollenbezeichnung |
Siehe auch TableModel und 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.