Results 1 to 3 of 3

Thread: Display a subfolder from QDirModel with QTreeView

  1. #1
    Join Date
    Feb 2015
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Display a subfolder from QDirModel with QTreeView

    My code below will display the whole file system. I just want to display a subfolder (ex D:\folder1), with all it's contents.
    I tried setting the root index of the treeView but this will hide the folder (only the contents of the folder1 will be shown).
    I also tried using "setFilterRegExp()" and "setFilterKeyColumn()", but this approach will also NOT work because it will filter the parents as well.
    I also tried subclassing the QSortFilterProxy" but that seems a little too much for what I'm trying to achieve.

    Is there an easier method here?

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QDirModel *model = new QDirModel();
    5. QSplitter *splitter = new QSplitter();
    6. QTreeView *leftTree = new QTreeView(splitter);
    7.  
    8. proxyModel->setSourceModel(model);
    9. leftTree->setModel(proxyModel);
    10.  
    11. splitter->show();
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,117
    Thanks
    235
    Thanked 656 Times in 646 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Display a subfolder from QDirModel with QTreeView

    Probably you need to retrieve the QModelIndex for the folder you are interested in using QDirModel::index() and then set that as the root index on the tree view. I'm not sure what you hope to accomplish with a proxy model.

  3. #3
    Join Date
    Feb 2015
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Display a subfolder from QDirModel with QTreeView

    That works, but it will only display the contents at that path(or children in the model), I want to have the folder too, like this:

    setRootIndex() will display:

    ---SubFolder1
    ---File1
    ---etc

    I want:

    -Folder1
    ---SubFolder1
    ---File1
    ---etc

Similar Threads

  1. QTreeView and QDirmodel 's problem?
    By ggs0110 in forum Qt Programming
    Replies: 8
    Last Post: 31st July 2012, 12:11
  2. Add Item in QDIRMODEL + QTREEVIEW
    By kamlmish in forum Newbie
    Replies: 0
    Last Post: 7th January 2011, 08:35
  3. QDirModel, QTreeView, and QListView
    By gimmejimmy in forum Newbie
    Replies: 2
    Last Post: 24th June 2009, 06:41
  4. QDirModel and a QTreeView.
    By jamd in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 09:41
  5. QDirModel and QTreeView
    By ChMaster in forum Qt Programming
    Replies: 8
    Last Post: 13th April 2006, 20:27

Tags for this Thread

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.