Qt tree view with Pyside

2019-09-01 03:28发布

问题:

I have two folders in program directory. I need them to show in tree view, they should be expandable. How can I define what folder will be in tree view? If anyone canshow me an easy example. I know names of folders.

I´m using Python 2.7 and Win 8.

回答1:

You can do that with QTreeView and QFileSystemModel:

model = QFileSystemModel();
model.setRootPath(QDir.currentPath())
tree = QTreeView()
tree.setModel(model)
tree.setRootIndex(model.index(QDir.currentPath()))
tree.show()