Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QML TreeView from C++ QAbstractItemModel
Forum Updated to NodeBB v4.3 + New Features

QML TreeView from C++ QAbstractItemModel

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.2k Views 1 Watching
  • 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.
  • K Offline
    K Offline
    Korchkidu
    wrote on last edited by
    #1

    Hi,

    I have a custom C++ QAbstractItemModel that is working nicely when using Qt Widget QTreeView. Now, I want to use the C++ model directly in QML.

    I got inspired by the following article:
    http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView

    In particular, creating a recursive delegate seems the way to go. My current QML is:
    @ Component
    {
    id: sceneNodeDelegateRec

    Column
    {
      id: columnRec
      Text
      {
    
        id: text
        text: model.modelData // use qualified names for clarity sake
        color: "white"
      }
    
      Repeater
      {
        id: repeaterRec
        model: model.getChildren() // <<== TypeError: Cannot call method 'getChildren' of undefined
        delegate: sceneNodeDelegateRec
      }
    }
    

    }

    ListView
    {
    id: sceneGraphView
    anchors.fill: parent
    model: sceneGraphModel
    delegate: sceneNodeDelegateRec
    }@

    So my questions are:
    1) How can I reference "parent model" in the recursive delegate's Repeater;
    2) How can I pass to Repeater.model the children of parent model doing something like parentModel.getChildren()?

    Thanks for any help.
    Best regards.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Korchkidu
      wrote on last edited by
      #2

      Any idea? Anyone?

      Thanks in advance.
      Best regards.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DimanNe
        wrote on last edited by
        #3

        I do not know, but you definitely can Vote for "this bug":https://bugreports.qt-project.org/browse/QTBUG-29886?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-236957

        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