The QStandardItemModel reference gives an example of how to use it for a TreeView:
QStandardItemModel model;
QStandardItem *parentItem = model.invisibleRootItem();
for (int i = 0; i < 4; ++i) {
QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
parentItem->appendRow(item);
parentItem = item;
}
Next to this you can add the model to QML with the following:
view.rootContext.setContextProperty("treeViewModel", model);
You also need the root item from the model to show everything in the Treeview:
view.rootContext.setContextProperty("root", model.indexFromItem(model.invisibleRootItem()));
Now you can add it to you QML TreeView like follows:
TreeView{
model: treeViewModel
rootItem: root
TableViewColumn {
role: "display" // is role 0
}
}
QStandardItemModel
. Here is simple example how to do that. – folibis