In PyQt5, I have a QTreeView tree_view
that has a model called file_model
. I tried to set the root index by calling file_model.setRootPath(os.getcwd() + "/sets")
then calling tree_view.setRootIndex(file_model.index("sets"))
. However, my program only shows the child folders of the directory sets
, but the parent folder.
A snippet of my code:
self.file_model = QtWidgets.QFileSystemModel()
self.file_model.setRootPath(getcwd() + "/sets")
self.file_model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)
self.tree_view = QtWidgets.QTreeView()
self.tree_view.setModel(self.file_model)
self.tree_view.setRootIndex(self.file_model.index("sets"))
However, this is shown:
The problem is that I also want to show the parent directory sets
. What is a way to do that in PyQt5?