PDA

View Full Version : QTreeView and multiple models



Daher
6th October 2008, 22:51
In my program, I need to create multiple trees from different sources.. one of the subtrees is the local disk using "QDirModel" .. the other subtree in the same view is an ftp site using a custom QCustomFtpModel that works just like qdirmodel..

so I was wondering if anyone could help me plan this out.

is creating a proxy with a function, say: addSubTreeModel( location_index, new_model )

seem to be possible to you? these things aren't very well documented in qt so I think this will be painful.. any ideas ?

jacek
19th October 2008, 21:17
All you need is a custom model that maps subtrees to submodels.

drkvogel
2nd December 2019, 17:34
In my program, I need to create multiple trees from different sources.. one of the subtrees is the local disk using "QDirModel" .. the other subtree in the same view is an ftp site using a custom QCustomFtpModel that works just like qdirmodel..

Did you find a way to do this? I want to do a similar thing: I want a treeview that shows multiple subtrees of the filesystem. Please let me know if you found a solution!

d_stranz
3rd December 2019, 20:57
After more than 11 years, do you think the OP is listening?

As jacek said, you need to derive a custom QAbstractItemModel that contains (as member variables) pointers to each of your file system subtrees. Each of these subtrees can either be a new QFileSystemModel instance with its root path set to the appropriate spot in the file system hierarchy, or it can be a single QFileSystemModel instance, and you keep separate, persistent QModelIndex values for each of the entry points for your subtrees.

You will then have to re-implement all of the QAbstractItemModel member functions so you can map from your custom model's indexes to the indexes used by the QFileSystemModel(s).

This will not be easy, and I am certain you will spend a lot of time trying to get it right.

Personally, I think it would be far easier to implement separate tree views, each with its own QFileSystemModel instance. Put these in a vertical layout inside of a QScrollView.