Unsolved How to show root directory in QFileSystemModel
-
i have a following directory setup... root->childFolder, ChildFile... when i set filesystemmodel for root directory, QTreeView only shows childFolder and childFile, not the root directory itself.. one more thing, i want to hide expansion icon (+) on empty directory.. how could i implement these 2 features??
-
Hi,
Can you show the code you are using ?
-
QTreeView *tree = new QTreeView(this); QFileSystemModel *model = new QFileSystemModel(this); tree->setModel(model); model->setRootPath(path); tree->setRootIndex(model->index(path));
here path is "/home/home/test1".. there are 3 folders under test1: image, others and pdf. tree view shows them, but i want to show parent directory aka "test1" on top of them. one more thing - 'pdf' folder is empty. but still treeview shows expansion / hide icon (+, -) for it. here is a screenshot
-
This post is deleted! -
@SGaist said in How to show root directory in QFileSystemModel:
Hi,
Can you show the code you are using ?
sure
-
@abdullahzubair109
I've never used this stuff, but is it yoursetRootIndex()
which is wrong?
https://stackoverflow.com/questions/50357948/difference-between-setrootpath-and-setrootindex-in-qfilesystemmodelso the rootIndex() of the model should not be the root that is shown in the view.
Try playing with it/removing it, see what happens?
Does it need to be the parent (/home/home
) of the root directory (test1
) you wish to show in the tree? -
@JonB in that case all directories under "home/home" will be shown too..I will have to filter out those directories..
-
@abdullahzubair109
Remember I have never used this, but I was thinking:setRootPath("/home/home") setRootIndex("/home/home/test1")
? So perhaps it would be
setRootPath()
which you would change from what you have now.EDIT I think https://forum.qt.io/topic/7636/qtreeview-root-node-isn-t-shown is what you're looking for?
or https://forum.qt.io/topic/67472/qtreeview-shows-all-the-subfolders-but-not-the-parent-folder
or https://forum.qt.io/topic/74756/show-root-path-in-qtreeview-for-qfilesystemmodel -
@JonB changing setRootPath didn't work...
-
@JonB i will have to use QSortFilterProxyModel then..