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 use QML listview with c++ treemodel
Forum Updated to NodeBB v4.3 + New Features

How to use QML listview with c++ treemodel

Scheduled Pinned Locked Moved QML and Qt Quick
18 Posts 4 Posters 7.0k 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.
  • D Offline
    D Offline
    Dragann
    wrote on last edited by
    #1

    is it possible to display all the children of an item in a c++ treemodel subclassed from QAbstractItemModel?

    i am having a lot of difficulty with this because all examples that i can find are with simple lists.. none are with treemodels..

    Thanks in advance

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dragann
      wrote on last edited by
      #2

      if anyone could point me into the right direction, i would be extremely happy... i have been struggling with this the whole day but i just cannot seem to get it right

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        QML does not support trees. Only list models are officially supported. This will change in Qt 5.5.

        Some people have provided alternative, unofficial solutions.

        (Z(:^

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dragann
          wrote on last edited by
          #4

          ah i see,, so i would have to create custom listmodels on demand from the data in the treemodel,, and then use it to populate the listview

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            [quote author="Dragann" date="1424347240"]ah i see,, so i would have to create custom listmodels on demand from the data in the treemodel,, and then use it to populate the listview[/quote]

            So far, yes, that is a kind of solution.

            (Z(:^

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

              You could check this example out:

              http://qt-project.org/forums/viewthread/30521/

              Otherwise you will have to wait until Qt 5.5 for the official release for a TreeView.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                Dragann
                wrote on last edited by
                #7

                Thanks onek24, i allready found that post,, the problem for me is, they make a model in qml,, i wasnt able to figure out yet how to do it with a model from c++,, but that just means i dont have enough skill yet :(

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  Dragann
                  wrote on last edited by
                  #8

                  i have found some more information on the QML c++ treemodel stuff..
                  for people who are looking for more info

                  "translate the page with Chrome":http://qt-way-notes.blogspot.nl/2010/07/tree-model-qml.html

                  "more stuff":https://lemirep.wordpress.com/2013/04/06/a-practical-case-exposing-qt-c-models-to-qml/

                  "some source code to the above link":https://gitorious.org/tepee3d/tepee3d/source/2df4d84b0835fa426c388db8416605ec3a4d4f6f:Tepee3DEngine/DeveloperAPIFiles/Models

                  "another article on treemodels in qml":http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jsprenkle
                    wrote on last edited by
                    #9

                    This might be helpful to you:
                    http://www.informit.com/articles/article.aspx?p=1405547&seqNum=3
                    He shows how to create non list type models

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      Dragann
                      wrote on last edited by
                      #10

                      thanks jsprenkle. I have the book and i have read the model chapters but it is not about QML, so i cannot really use it, aside from the c++ side of the application ofcourse.

                      i allready have built a treemodel in c++,, now i only need to show it like i want in qml

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

                        You might combine "this information":http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html with the link to the TreeView i posted above.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          Dragann
                          wrote on last edited by
                          #12

                          @onek24, thanks for taking the time to help me out!

                          i have read those docs already but im having difficulty connecting all the different parts.. so i have given up on creating a treeview and now i am trying to create a bunch of listviews and display them dynamically using QQmlListProperty... Maybe i will try out this stuff again later

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

                            I think it should work if you just pass your treemodel to QML and set the model of your treeview to the passed treemodel. Maybe taking some modifications on the variable names but that should be all.

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              Dragann
                              wrote on last edited by
                              #14

                              i have come to understand that its not possible to use treemodel with QML directly but maybe i understood that wrong... anyways, my treeview in QML is just a bunch of nested listview.. are you saing its possible to pass the treemodel directly to the lists?

                              i have filled my treemodel with QList containers of listmodels.. and i have made functions that fill the QLists with the data inside the treemodel.. so its basically a bunch of 1d models inside a QAbstractItemModel tree..

                              and through QQmlListproperty and some index functions i am able to assign the models to the listviews.. it seems to work now,, but it is quick and dirty

                              maybe i will have to switch to a better method later

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

                                Or you'll wait for Qt 5.5, you can find the release-plan here: "Qt 5.5 Release":http://qt-project.org/wiki/Qt-5.5-release

                                Maybe the Alpha or Beta has already an implemented treeview?

                                1 Reply Last reply
                                0
                                • D Offline
                                  D Offline
                                  Dragann
                                  wrote on last edited by
                                  #16

                                  awesome! i will definitely take a look at that.. really hope the alpha or the beta have the treeview included already. I will manage to find a way no matter what :p

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

                                    Soon i'll probably need a qml treeview with a c++ treemodel too, so i'll provide you the code when it's done and if the plans have not changed. But it will be just a temporary solution until the official treeview comes out.

                                    1 Reply Last reply
                                    0
                                    • D Offline
                                      D Offline
                                      Dragann
                                      wrote on last edited by
                                      #18

                                      thanks! :D and yeah the new QT is coming pretty soon... we will see :)

                                      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