Python PyQt QFileSystemModel根路径 [英] Python PyQt QFileSystemModel Root Path
本文介绍了Python PyQt QFileSystemModel根路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我必须显示名为"C:\ Myfolder"的目录的树状视图的代码.
This is the code i have to display a tree view of a directory called "C:\Myfolder".
import sys
from PyQt4 import QtGui,QtCore
class Myview(QtGui.QMainWindow):
def __init__(self,parent=None):
QtGui.QMainWindow.__init__(self)
model = QtGui.QFileSystemModel()
model.setRootPath('C:\Myfolder')
view = QtGui.QTreeView()
view.setModel(model)
self.setCentralWidget(view)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myview = Myview()
myview.show()
sys.exit(app.exec_())
即使我将RootPath
设置为"C:\ Myfolder",树形视图也会显示所有驱动器和文件夹.
Even though i set the RootPath
to "C:\Myfolder" , the tree view display all the drives and folder.
如何限制QFileSystemModel
,以便TreeView
仅显示"C:\ Myfolder"目录中的项目?
How can i limit the QFileSystemModel
so that TreeView
only display items inside "C:\Myfolder" directory?
推荐答案
您需要根据 查看全文