PyQt:QFileSystemModel 中的当前目录
我正在使用一些官方示例中的以下代码:
model = QFileSystemModel()
model.setRootPath(QDir.currentPath())
view = QTreeView(parent=self);
view.setModel(model)
我希望它能够在树视图中展开目录结构,以便显示运行我的程序的目录。然而,我得到的是从文件系统根开始的未展开的树。我怎样才能做对呢?
我尝试使用 expand
,但没有帮助:
model = QFileSystemModel()
index = model.index(QDir.currentPath())
view = QTreeView(parent=self);
view.setModel(model)
view.expand(index)
树视图仍然未展开。
I am using following code from some official example:
model = QFileSystemModel()
model.setRootPath(QDir.currentPath())
view = QTreeView(parent=self);
view.setModel(model)
I expected it to expand directory structure in the tree view so directory from which my program is run would be displayed. What I get, however, is unexpanded tree starting with file system root. How can I make it right?
I tried using expand
, but it didn't help:
model = QFileSystemModel()
index = model.index(QDir.currentPath())
view = QTreeView(parent=self);
view.setModel(model)
view.expand(index)
The tree view is still unexpanded.
您必须使用QTreeView.expand。
You would have to use QTreeView.expand.