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. Tree view
Forum Updated to NodeBB v4.3 + New Features

Tree view

Scheduled Pinned Locked Moved Solved QML and Qt Quick
11 Posts 3 Posters 2.8k 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 krojew

    Hi,
    I'm quite new to QML and I'm struggling to find any information how to render a tree model in a simple way (although horizontally, rather than vertically):

    alt text

    Seems like QML only supports list data structures from models. Is there any way to do it?

    E Offline
    E Offline
    Eeli K
    wrote on last edited by
    #2

    @krojew There's TreeView in Controls 1. Lack of a tree view is a well known deficiency in Controls 2. You can use a QAbstractItemModel based C++ model in QML.

    K 1 Reply Last reply
    0
    • E Eeli K

      @krojew There's TreeView in Controls 1. Lack of a tree view is a well known deficiency in Controls 2. You can use a QAbstractItemModel based C++ model in QML.

      K Offline
      K Offline
      krojew
      wrote on last edited by
      #3

      @Eeli-K TreeView, as far I can see, is unable to render a tree in a way shown in that picture.

      E 1 Reply Last reply
      0
      • K krojew

        @Eeli-K TreeView, as far I can see, is unable to render a tree in a way shown in that picture.

        E Offline
        E Offline
        Eeli K
        wrote on last edited by
        #4

        @krojew Oh, I thought it was an abstraction. There's no other option than handle the items and locations manually like in any other GUI library (I don't think there's any first-party ready-made solution for any general toolkit). Your best bet is to find an application with a liberal licence which fits your needs and copy some code.

        1 Reply Last reply
        0
        • GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #5

          You could do that with nested DelegateModels and the rootIndex property.

          K 1 Reply Last reply
          0
          • GrecKoG GrecKo

            You could do that with nested DelegateModels and the rootIndex property.

            K Offline
            K Offline
            krojew
            wrote on last edited by
            #6

            @GrecKo I took a look at that, but I don't see how to use it. DelegateModel requires to use some view to actually display the data. What would that view be in this case? Especially since I need children of different parents, but on the same level, to actually be rendered in the same column/row.

            1 Reply Last reply
            0
            • GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by
              #7

              I'd go with a Repeater and maybe a Column of Rows.
              Maybe manually parenting delegate to a specific Row

              K 1 Reply Last reply
              0
              • GrecKoG GrecKo

                I'd go with a Repeater and maybe a Column of Rows.
                Maybe manually parenting delegate to a specific Row

                K Offline
                K Offline
                krojew
                wrote on last edited by
                #8

                @GrecKo do you have any example code? I don't really know how mix all of those. Sounds like some kind of recursive QML.

                1 Reply Last reply
                0
                • GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #9

                  No, but it would help if you would provide a simple tree model to test my idea.
                  Like one with the same data as the image in your first post.

                  I won't be able to try before monday, but I think I'll do it since it's interesting.

                  K 1 Reply Last reply
                  0
                  • GrecKoG GrecKo

                    No, but it would help if you would provide a simple tree model to test my idea.
                    Like one with the same data as the image in your first post.

                    I won't be able to try before monday, but I think I'll do it since it's interesting.

                    K Offline
                    K Offline
                    krojew
                    wrote on last edited by
                    #10

                    @GrecKo you can use QDirModel from the example here: http://doc.qt.io/qt-5/qml-qtqml-models-delegatemodel.html#rootIndex-prop

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      krojew
                      wrote on last edited by krojew
                      #11

                      I got it working using recursive qml and a bunch of row/column layouts with repeaters. Now I have a new problem: I'm using incubateObject() to asynchronously create the same component I'm currently in for children, when the current component is completed. And for some reason, that incubateObject call seems to be synchronous since the whole ui freezes for large trees and everything suddenly pops up.

                      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