How to use QML listview with c++ treemodel
-
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
-
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.
-
[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.
-
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 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?