Python PyQt QFileSystemModel根路径
这是我必须显示名为“C:\Myfolder”目录树视图的代码 即使我将Python PyQt QFileSystemModel根路径,python,pyqt,pyqt4,qfilesystemmodel,Python,Pyqt,Pyqt4,Qfilesystemmodel,这是我必须显示名为“C:\Myfolder”目录树视图的代码 即使我将RootPath设置为“C:\Myfolder”,树视图也会显示所有驱动器和文件夹 如何限制QFileSystemModel以便TreeView仅显示“C:\Myfolder”目录中的项目?您需要根据添加view.setRootIndex(model.index(“C:\Myfolder”)。此处提供了另一个相同解决方案的解释: import sys from PyQt4 import QtGui,QtCore class
RootPath
设置为“C:\Myfolder”,树视图也会显示所有驱动器和文件夹
如何限制
QFileSystemModel
以便TreeView
仅显示“C:\Myfolder”目录中的项目?您需要根据添加view.setRootIndex(model.index(“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_())