Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python PyQt QFileSystemModel Root Path

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_())

Even though i set the RootPath to "C:\Myfolder" , the tree view display all the drives and folder.

How can i limit the QFileSystemModel so that TreeView only display items inside "C:\Myfolder" directory?

like image 657
Chris Aung Avatar asked Nov 13 '13 07:11

Chris Aung


1 Answers

You would need to add view.setRootIndex(model.index("C:\Myfolder")) according to the QFileSystemModel documentation.

like image 138
Ramchandra Apte Avatar answered Nov 02 '22 10:11

Ramchandra Apte