问题
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):
Seems like QML only supports list data structures from models. Is there any way to do it?
回答1:
Figured it out on my own. The trick is to use DelegateModel, Repeater and Row/Column layouts, not TreeView.
- Create a component which will show your current node using DelegateModel.
- Use a Repeater to create children - let the component dynamically create another instance of itself, assign the current node as the rootIndex of newly constructed DelegateModel, and set it as the model for the Repeater.
- By properly using layouts, you can position your nodes exactly as in the attached image.
来源:https://stackoverflow.com/questions/45866647/qml-tree-view-from-a-model