I\'m trying to create a correct Treeview with Qml Qt 5.5. I succeed to have a Treeview with a global root. But impossible to find how to add child for row item.
For
You can also create a TreeModel class that extends QStandardItemModel
and overrides roleNames()
, like done here. To add children to nodes in your tree, just use appendRow()
.
TreeModel::TreeModel(QObject *parent) : QStandardItemModel(parent)
{
QStandardItem *root = new QStandardItem("root");
QStandardItem *child = new QStandardItem("child");
this->appendRow(root);
root->appendRow(child);
}