QML tree view from a model

元气小坏坏 提交于 2019-12-13 03:46:49

问题


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.

  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.


来源:https://stackoverflow.com/questions/45866647/qml-tree-view-from-a-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!