pyqtlisttree如何显示文件目录
时间: 2023-08-14 12:06:06 浏览: 51
要在 PyQt 中显示文件目录,可以使用 QTreeView 和 QFileSystemModel 类。下面是一个简单的示例代码:
```python
from PyQt5.QtWidgets import QApplication, QTreeView
from PyQt5.QtCore import QDir, QFileSystemModel
app = QApplication([])
model = QFileSystemModel()
model.setRootPath(QDir.currentPath())
tree = QTreeView()
tree.setModel(model)
tree.setRootIndex(model.index(QDir.currentPath()))
tree.show()
app.exec_()
```
在这个示例中,我们首先创建了一个 QFileSystemModel 对象,然后设置它的根目录为当前目录。接下来,我们创建一个 QTreeView 对象,并将 QFileSystemModel 对象设置为其模型。最后,我们将 QTreeView 对象的根索引设置为当前目录的索引,并显示它。
运行这个程序,就可以在 PyQt 中显示当前目录的文件目录了。