Results 1 to 4 of 4

Thread: treeview show dirs and tableview show files with one filesystemmodel?

  1. #1
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default treeview show dirs and tableview show files with one filesystemmodel?

    playing with this example.
    ttp://doc.qt.nokia.com/4.6/model-view-using.html

    how can I make the treview display only directories and the table view only files? If I change something in the model with setfilter, both react to it.
    thanks

  2. #2
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: treeview show dirs and tableview show files with one filesystemmodel?

    sorry, I mean there is something like QSortFilterProxyModel but that does not have the convenient setFilter for dirs, files etc.

  3. #3
    Join Date
    Jul 2009
    Posts
    92
    Thanks
    7
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: treeview show dirs and tableview show files with one filesystemmodel?

    ok found it for those who are interested:
    I use two models, one for the treeview (QDirModel) and one for the tableview (QFileSystemModel)
    then when the directory is changed in the treeview, I set the setRootPath of the QFileSystemModel
    Qt Code:
    1. ...
    2. QModelIndex dir = index.sibling(index.row(), 0);
    3. if (dir != fileView->rootIndex() && dirModel->isDir(dir))
    4. {
    5. currentPath = dirModel->filePath(dir);
    6. treeView->setCurrentIndex(index);
    7.  
    8. fileModel->setRootPath(currentPath);
    9. fileView->setRootIndex(fileModel->index(currentPath));
    10. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: treeview show dirs and tableview show files with one filesystemmodel?

    You could of course subclass the QSortFilterProxyModel as well...
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

Similar Threads

  1. Replies: 9
    Last Post: 28th April 2010, 09:18
  2. Replies: 2
    Last Post: 24th September 2009, 00:49
  3. updating treeview from tableview
    By darshan in forum Qt Programming
    Replies: 4
    Last Post: 11th February 2009, 19:53
  4. How to show custom widget in TreeView's cell :-/
    By WolfMM in forum Qt Programming
    Replies: 2
    Last Post: 7th July 2007, 11:16
  5. TreeView, TableView
    By rbrand in forum Qt Programming
    Replies: 1
    Last Post: 4th July 2006, 08:54

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.