0

Using Qt's model-view framework to represent a tree structure, such as Qt provided simple tree example, the tree view shows the root-tree-item. Any way to show a sub-tree-item, such as a child item of the root?

user2052376
  • 117
  • 1
  • 6

1 Answers1

1

The documentation for Qt's model/view framework covers this.

In short, these methods determine the structure of your tree:

  • QAbstractItemModel::index(), which should return the child indices of a given parent index
  • QAbstractItemModel::parent(), which should return the parent index of a given child

Note that if you have a large view, these methods must be fast, because the Qt item views will call them very often.


If you don't absolutely need to implement your own model , I would also suggest looking at QTreeWidget (instead of QTreeView), which is a much simpler, retained-mode tree view widget. It provides most of the same features with a much easier-to-use (and less error-prone) conceptual model.

jmk
  • 1,938
  • 14
  • 15