How to Insert/Update/Remove in a C++ TreeModel and a QML View



  • Hello,

    I need for my QML UI to use a TreeView.
    I based my TreeViewModel from this example

    I use custom Data and they are displayed correctly. However, I have trouble to understand how I could update the view when I need for example to insert a new Data.

    When using for example a QAbstractListModel, I will use functions like beginInsertRows() etc.
    It is easy to find the index because you have a QList of Data.
    However, in a TreeModel, the only Data you have is the root of the TreeItem.

    So I don't know what index to give to beginInsertRows() if I want to insert (or update or remove) a Node.
    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 !



    1. Check Editable Tree Model Example.
    2. Item delegate has styleData.index special property that holds QModelIndex.


  • Thanks a lot !


Log in to reply