I'm building an open source PySide6 app based on the custom file browser in QTreeView
.
I've already subclassed QFileSystemModel
to display a custom column with some extra data.
Now my goal is to display a specific subset of files (they can be located on different drives) in a treeview.
To simplify things imagine that I have a function:
def files_to_display():
return ['C:\file1', 'D:\file2', 'D:\file3']
Now I need to display these files in my QTreeView
. I tried using QSortFilterProxyModel
and filterAcceptsRow
to filter out everything else and it worked. However on a relatively large number of files it's extremely slow and unusable. I'm pretty sure a simpler custom file tree would work faster because afaik QFileSystemModel
tracks the folder state and runs other extra stuff that I can live without.
I'm not sure how to solve this problem. I see basically 2 ways:
Somehow cut out what I don't need from
QFileSystemModel
. With this solution I don't fully understand how I do this. In particular, how do I fill the model with the data from my function? How do it usesetRootPath
?Subclass
QAbstractItemModel
. This solution is more or less clear, however, it's missing some of the important things that go withQFileSystemModel
out of the box: I need the columns and the data it provides (name, size, type, modification date), I also need file/folder icons that I'm using withQFileIconProvider
.
So basically I'd like to use a light-weighted version of QFileSystemModel
without watching the file system and with my list of files.
I'm open to alternative solutions.