[Qt-interest] Tree and Table view on same model
Sean Harmer
sean.harmer at maps-technology.com
Tue May 18 16:49:28 CEST 2010
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.
Cheers,
Sean
More information about the Qt-interest-old
mailing list