QML tree view from a model

2019-09-15 10:33发布

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):

enter image description here

Seems like QML only supports list data structures from models. Is there any way to do it?

标签: c++ qt qml
1条回答
叛逆
2楼-- · 2019-09-15 11:10

Figured it out on my own. The trick is to use DelegateModel, Repeater and Row/Column layouts, not TreeView.

  1. Create a component which will show your current node using DelegateModel.
  2. 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.
  3. By properly using layouts, you can position your nodes exactly as in the attached image.
查看更多
登录 后发表回答