Results 1 to 4 of 4

Thread: QTreeView and multiple models

  1. #1
    Join Date
    Apr 2008
    Posts
    3

    Default QTreeView and multiple models

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeView and multiple models

    All you need is a custom model that maps subtrees to submodels.

  3. #3
    Join Date
    Nov 2019
    Posts
    1
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTreeView and multiple models

    Quote Originally Posted by Daher View Post
    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!

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView and multiple models

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Multiple clicks required to get into edit mode on QTreeView
    By JonInAnnArbor in forum Qt Programming
    Replies: 10
    Last Post: 26th November 2012, 19:59
  2. QTreeView with multiple models
    By Daher in forum Qt Programming
    Replies: 5
    Last Post: 18th October 2011, 11:53
  3. [QT4] QTreeView and rows with multiple lines
    By KShots in forum Qt Programming
    Replies: 8
    Last Post: 30th March 2006, 19:47
  4. Replies: 2
    Last Post: 10th March 2006, 19:04

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.