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?
Code:
int main(int argc, char *argv[])
{
proxyModel->setSourceModel(model);
leftTree->setModel(proxyModel);
splitter->show();
return a.exec();
}
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.
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