How to use QML listview with c++ treemodel
-
[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.
-
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.
-
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 :(
-
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
-
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 -
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
-
You might combine "this information":http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html with the link to the TreeView i posted above.
-
@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
-
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.
-
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
-
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?
-
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
-
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.
-
thanks! :D and yeah the new QT is coming pretty soon... we will see :)