How to display correctly Treeview with QML Qt 5.5

后端 未结 2 1494
醉话见心
醉话见心 2021-01-13 02:21

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

2条回答
  •  清酒与你
    2021-01-13 02:36

    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);
    }
    

提交回复
热议问题