Solved How to Insert/Update/Remove in a C++ TreeModel and a QML View
-
Hello,
I need for my
QML
UI to use aTreeView
.
I based my TreeViewModel from this exampleI use
custom Data
and they are displayed correctly. However, I have trouble to understand how I couldupdate
the view when I need for example toinsert
anew Data
.When using for example a
QAbstractListModel
, I will use functions likebeginInsertRows()
etc.
It is easy to find theindex
because you have aQList
ofData
.
However, in aTreeModel
, the only Data you have is the root of theTreeItem
.So I don't know what
index
to give tobeginInsertRows()
if I want to insert (or update or remove) aNode
.
Could someone explain it to me ?I don't know if my explanation was clear, my english is not perfect. If you have trouble to understand my question, just tell me and I will try to make it more clear.
Thanks a lot and have a good day !
-
- Check Editable Tree Model Example.
- Item delegate has
styleData.index
special property that holds QModelIndex.
-
Thanks a lot !