In Qt Quick Controls 1 we can style different columns from a model with TableViewColumn:
TableView {
anchors.fill: parent
TableViewColumn {title: "1"; role: "one"; width: 70 }
TableViewColumn {title: "2"; role: "two"; width: 70 }
TableViewColumn {title: "3"; role: "three"; width: 70 }
model: theModel
}
How can we achieve a similar result in Qt Quick 2 if there is no more TableViewColumn for the TableView?
Since Qt 5.12 you can use
TableViewQML type. But to have everything you want you need to includeQt.labs.qmlmodels. It all is available in Qt 5.15 (use online installer).Actual implementation will hardly depend on your requirements, but here is an example of how it could be done.
Let's say you are going to use
TableViewto show some data you have in JSON format. In this caseTableModelwill be a perfect fit, since it is designed to work with JavaScript/JSON data, where each row is a simple key-pair object without requiring the creation of a customQAbstractTableModelsubclass in C++.You need to declare what columns do you need to have in your model by using
TableModelColumn, e.g.:TableModelColumn { display: "checked" }.For loading real data into model use its
rowsproperty; data should be in the form of an array of rows, e.g.:DelegateChooser, since it allows a view to use different delegates for different types of items in the model. So here you can do almost everything to tweak your cells. E.g.: you can useProgressBarcomponent as your delegate for a cell:As result you could easily get this application entirely in QML (whiteout need to use C++ and/or old QtQuick.Controls):
Please refer to this repository to get full application.