简体   繁体   English

模型的QML树视图

[英]QML tree view from a model

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): 我对QML还是很陌生,我正在努力寻找任何信息以简单的方式(尽管是水平而不是垂直)渲染树模型:

在此处输入图片说明

Seems like QML only supports list data structures from models. 似乎QML仅支持来自模型的列表数据结构。 Is there any way to do it? 有什么办法吗?

Figured it out on my own. 我自己弄清楚了。 The trick is to use DelegateModel, Repeater and Row/Column layouts, not TreeView. 诀窍是使用DelegateModel,Repeater和Row / Column布局,而不是TreeView。

  1. Create a component which will show your current node using DelegateModel. 创建一个组件,该组件将使用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. 使用Repeater创建子级-让组件动态创建其自身的另一个实例,将当前节点分配为新构建的DelegateModel的rootIndex,并将其设置为Repeater的模型。
  3. By properly using layouts, you can position your nodes exactly as in the attached image. 通过正确使用布局,您可以将节点完全定位在所附图像中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM