0

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:

enter image description here

The problem is that I also want to show the parent directory sets. What is a way to do that in PyQt5?

Evan Zhao
  • 70
  • 1
  • 7

0 Answers0