[Qt-interest] Tree and Table view on same model
Sean Harmer
sean.harmer at maps-technology.com
Tue May 18 17:20:29 CEST 2010
On Tuesday 18 May 2010 15:56:07 Andre Somers wrote:
> On 18-5-2010 16:51, Sean Harmer wrote:
> > On Tuesday 18 May 2010 15:49:28 Sean Harmer wrote:
> >> Hi,
> >>
> >> On Tuesday 18 May 2010 15:35:04 Jonathan Lee wrote:
> >>> Hi all,
> >>>
> >>> not an expert on Qt so I hope this isn't too trivial.
> >>>
> >>> I'd like a Tree and Table view on the same model, where
> >>>
> >>> the tree shows a structure, and the table shows the leaves
> >>> of the selected item of the tree.
> >>>
> >>> Specifically I have a zip viewer which shows the dirs
> >>>
> >>> on the left in a tree, and the files in that dir on the
> >>> right in a table.
> >>>
> >>> Right now I'm doing these two models separately, but
> >>>
> >>> it seems redundant.
> >>>
> >>> What's the usual way of handling this? Make a proxy
> >>>
> >>> model for both views, using a common model? Or is
> >>> there a cleaner way?
> >>
> >> Use a single model on both views. Then when the user clicks on a node
> >> (or activates it by some other means) in the tree view call
> >> setRootIndex() on your table view so that the table only shows the
> >> indexes below that root.
> >>
> >> See:
> >>
> >> http://doc.qt.nokia.com/4.7-snapshot/qabstractitemview.html#activated
> >> http://doc.qt.nokia.com/4.7-snapshot/qabstractitemview.html#setRootIndex
> >>
> >> Just connect these together and you are done.
> >
> > Oh as André mentioned you may want to filter out the leaf nodes from the
> > tree view by using a proxy model between the source model and the tree
> > view. The table view can operate directly on the source model since you
> > are "filtering" out the structural nodes by using setRootIndex().
> >
> > Cheers,
> >
> > Sean
> >
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> Don't you run into problems if you use a model index from a filtered
> model in setRootIndex for a view that operates on an unfiltered model? I
> think you at least need to set the modelindex from the root model
> (obtained with QAbstractProxyModel::mapToSource()) with setRootNode.
>
> This blog http://steveire.wordpress.com/ has some interesting posts
> about such issues.
Yes indeed you will need to map the index to the source model.
Sean
More information about the Qt-interest-old
mailing list