PDA

View Full Version : Display a subset of the QAbstractItemModel



youngw
6th November 2010, 00:22
I've created a QAbstractItemModel and uses a tree view to show its contents. What I want to do next is to create another tree view to show a subset of the model. Should I make a copy of a portion of the original model (is there a quick way to do that)? or should the new tree view references the same model? if so, how would the new tree shows a subset of the model ?(say from a ModelIndex to another ModelIndex)

wysota
6th November 2010, 00:29
In the second view you should use an instance of QSortFilterProxyModel that will filter out the rows from the original model that you don't want.

youngw
6th November 2010, 05:39
Thanks.
In the first view, I've created indices for the items in the model in the data() function.
In the second view (if I used QSortFilterProxyModel as the model), do I have to createIndex() in the data() function again.
thanks in advance.

Added after 14 minutes:

Also, is there a code example for QSortFilterProxyModel if I want to display all children of a node of a tree model but not its parents.

wysota
6th November 2010, 09:33
You never use createIndex() in the data() method. And it's a method of the model, not of the view. I suggest you do some reading on the model-view architecture in Qt, your questions suggest you have very little knowledge of it.