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?
Asked
Active
Viewed 708 times
0
-
I am not sure what the problem is really. Have you had a look at the QTreeView class? – Daniel Hedberg Feb 16 '13 at 18:19
1 Answers
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 indexQAbstractItemModel::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