Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DataSolveProblems/6e37710831d9a1f42f9f8375cd914642 to your computer and use it in GitHub Desktop.
Save DataSolveProblems/6e37710831d9a1f42f9f8375cd914642 to your computer and use it in GitHub Desktop.
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTreeView, QFileSystemModel, QVBoxLayout
from PyQt5.QtCore import QModelIndex
class FileSystemView(QWidget):
def __init__(self, dir_path):
super().__init__()
appWidth = 800
appHeight = 300
self.setWindowTitle('File System Viewer')
self.setGeometry(300, 300, appWidth, appHeight)
self.model = QFileSystemModel()
self.model.setRootPath(dir_path)
self.tree = QTreeView()
self.tree.setModel(self.model)
self.tree.setRootIndex(self.model.index(dirPath))
self.tree.setColumnWidth(0, 250)
self.tree.setAlternatingRowColors(True)
layout = QVBoxLayout()
layout.addWidget(self.tree)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
dirPath = r'<Your directory>'
demo = FileSystemView(dirPath)
demo.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment