Solved How to get the index of a TreeItem in a TreeModel
-
I have a treeModel based on this example:
https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/itemviews/editabletreemodel
I would like to delete a specific item in the tree model, but this item is not selected. How can I get the index of a treeItem?
-
So how to do you know what item you want to delete?
See https://doc.qt.io/qt-5/model-view-programming.html#model-classes on how to get an index to an item -
If you just want to delete a certain row/column than you can use
QAbstractItemModel::index(int row, int column)
https://doc.qt.io/qt-5/qabstractitemmodel.html#indexHowever be sure to call beginRemoveRows() and endRemoveRows() when you're deleting it.
-
@gde23 It's a tree - the parent is important. Therefore my question...