krojew krojew - 1 year ago 173
C++ Question

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

enter image description here

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

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download