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 do you simulate a tree view in Qt Quick since it's not included in Controls 1.0?
Forum Updated to NodeBB v4.3 + New Features

How do you simulate a tree view in Qt Quick since it's not included in Controls 1.0?

Scheduled Pinned Locked Moved QML and Qt Quick
23 Posts 13 Posters 24.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.
  • H Offline
    H Offline
    hmuelner
    wrote on last edited by
    #13

    [quote author="loran" date="1393348350"]Unfortunately the example above crashes when I remove any element from the model when the folder in the view is expanded. Tested with Qt 5.2.0 and 5.2.1 on Linux. ...
    [/quote]

    With the current snapshot of Qt5.3-RC the crash does not happen any more. I get a message on the console: "TreeView.qml:15: TypeError: Cannot read property 'text' of null"

    Helmut Mülner

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hmuelner
      wrote on last edited by
      #14

      It would be really nice if the model could be a C++ QAbstractItemModel that is set with setContextProperty.

      Helmut Mülner

      1 Reply Last reply
      0
      • H Offline
        H Offline
        HennsWoerst
        wrote on last edited by
        #15

        I am trying to make this (really nice) view work with a QAbstractItemModel but I'm pretty much stuck -.-

        My first approach was to return the childItems of a node as model. I wrote a constructor in my model (of type QAbstractListModel) that took a QList<Node*> and returned a new model whenever the view wanted the subnodes of a node. This worked really well for read-only access, but is a mess regarding editing the tree, since I guess the models do not communicate to each other and a model has no idea what happens in another model. So if you delete a node in one model and another model wants to access the children of this model the whole thing crashes, because it does not know there is one node missing (that is my guess at least)

        So it seems the only solution for a consistent model is to have only one model that keeps track of every event that happens in the tree. So my second approach was the following: I returned the childnodes of a node as a QList<Node*> and made the data of a node accessible through the Q_PROPERTY macro, e.g. Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged). But now the view does not work anymore because the data of a QObject based model can only be accessed with model.modelData.role and not with model.role like in a QAbstractItemModel. The view would have to deal with two kinds of models and I do not know how to realize this.

        Can maybe anybody give me a hint on how I could make this work, it would be very much appreciated. Thank you.

        edit: I just realized the second approach would not work anyhow since the view would not be updated in a QObject based model.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          apmontgo
          wrote on last edited by
          #16

          If you want to make your own Qt Quick TreeView in C++, there's a presentation here:
          https://www.qtdeveloperdays.com/sites/default/files/north-america/QtQuickTreeView.pdf

          1 Reply Last reply
          0
          • A Offline
            A Offline
            apmontgo
            wrote on last edited by
            #17

            If you want to make your own Qt Quick TreeView in C++, there's a presentation here:
            https://www.qtdeveloperdays.com/sites/default/files/north-america/QtQuickTreeView.pdf

            1 Reply Last reply
            0
            • O Offline
              O Offline
              onek24
              wrote on last edited by
              #18

              [quote author="Jens" date="1381914126"]Here is an updated example using qt quick controls:

              ...[/quote]

              A very nice example. It seems like it's not that easy to implement key-events(up, down, ...) for controling this view. I would appreciate it if anyone could come up with an idea.

              1 Reply Last reply
              0
              • O Offline
                O Offline
                onek24
                wrote on last edited by
                #19

                [quote author="Jens" date="1381914126"]Here is an updated example using qt quick controls:

                ...[/quote]

                A very nice example. It seems like it's not that easy to implement key-events(up, down, ...) for controling this view. I would appreciate it if anyone could come up with an idea.

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #20

                  If you can wait a bit longer, there will be an official TreeView QML type in the upcoming "Qt 5.5 release":http://blog.qt.io/blog/2015/02/05/licensing-of-new-modules-in-qt-5-5/

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • JKSHJ Offline
                    JKSHJ Offline
                    JKSH
                    Moderators
                    wrote on last edited by
                    #21

                    If you can wait a bit longer, there will be an official TreeView QML type in the upcoming "Qt 5.5 release":http://blog.qt.io/blog/2015/02/05/licensing-of-new-modules-in-qt-5-5/

                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      onek24
                      wrote on last edited by
                      #22

                      Oh thats sweet, i'll wait until the official release. Thanks for your information.

                      1 Reply Last reply
                      0
                      • O Offline
                        O Offline
                        onek24
                        wrote on last edited by
                        #23

                        Oh thats sweet, i'll wait until the official release. Thanks for your information.

                        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