smerlin
smerlin

Reputation: 6566

QTreeView, QTableView, display items of different hierarchy layers

I want to display data using one custom Model (inherited from QAbstractItemModel), in a QTableView and a QTreeView.

My question is, is it possible to display all elements (i mean ALL elements, not just those from one hierarchy level) of the Model in the QTableView? So far i only managed to display items of one hierarchy level in a QTable View.

QTreeView:
-A
  -A1
  -A2
-B
  -B1
  -B2

QTableView // current behaviour
-A
-B

QTableView // desired behaviour
-A
-A1
-A2
-B
-B1
-B2

Upvotes: 2

Views: 2186

Answers (1)

user360907
user360907

Reputation:

What I would do here is use a proxy model to flatten the tree model before it got to the QTableView. Basically, it's a model that sits in front of your main model and serves it in a different format if the situation calls for it, but without affecting the model itself. You can read about how to do this with Qt here.

proxy model

Upvotes: 3

Related Questions