PDA

View Full Version : Displaying QAbstractItemModel in a Table



bmesing
28th March 2007, 09:30
Hello

I have a hierarchical QAbstractItemModel. For this model, I want to display all the items which are not at the top level in a simple list.

The Model:


parent1
+- child11
+- child12
parent2
+- child21
parent3
+- child31

should be displayed as:


child11
child12
child21
child31


I have tried to accomplish this by displaying the model in a QTableView, but this displays only the parent items. I have also tried to display the model in a QTreeView and hiding the parents, but unfortunately hiding the parent items does also hide their children.

Is there a way to do this except for writing a completly new view class? Perhaps subclassing QTreeView or QTableView in a smart way?

Any help would be appreciated.

Regards Ben

jpn
28th March 2007, 11:11
Is there a way to do this except for writing a completly new view class? Perhaps subclassing QTreeView or QTableView in a smart way?
Try implementing a proxy model (QAbstractProxyModel). There's an example of a Transpose Proxy Model (http://wiki.qtcentre.org/index.php?title=Transpose_Proxy_Model) in our wiki. It doesn't do at all what you want but gives you a simple idea how proxy models are implemented. What you should do is to map the children as top level indices.