Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to Insert/Update/Remove in a C++ TreeModel and a QML View
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fheanor
    wrote on last edited by
    #1

    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 Reply Last reply
    0
    • R Offline
      R Offline
      Ray Gray
      wrote on last edited by
      #2
      1. Check Editable Tree Model Example.
      2. Item delegate has styleData.index special property that holds QModelIndex.
      1 Reply Last reply
      2
      • F Offline
        F Offline
        Fheanor
        wrote on last edited by
        #3

        Thanks a lot !

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved