dinglewringle52
dinglewringle52

Reputation: 1

Showing files inside a directory with PyQt6 and QDir

I am trying to show files inside a directory in a ListView-Widget. Now everytime I enter a different path than the rootPath in the self.file_model.index(...) method, the window doesn't show any existing files in that folder. How do I manage to get the list view to show what is in that folder?

    self.file_list = QListView()
    main_layout.addWidget(self.file_list)
    
    self.file_model = QFileSystemModel()
    self.file_model.setFilter(QDir.Filter.Files)

    self.file_list.setModel(self.file_model)
    self.file_list.setRootIndex(self.file_model.index(r"C:\Users\...))

I tried to use dir with a list, but then it only shows the file names as strings. With QDir I tried to find a way to set it to a different directory but that didn't work either.

Upvotes: 0

Views: 334

Answers (1)

dinglewringle52
dinglewringle52

Reputation: 1

Solved it by giving the file_model a rootPath. self.file_model.setRootPath(r"C:\Users\..")

Upvotes: 0

Related Questions