[Interest] QSortFilterProxyModel filtering on QFileSystemModel
Sune Vuorela
nospam at vuorela.dk
Tue Mar 19 15:03:00 CET 2024
Hi
I've hitten a 'fun' corner where I found a surprising but documented
feature of QFileSystemModel and discovered how it interacted with
certain QSortFilterProxyModel configurations and QTreeView interactions
Assume the following:
Create a QSortFilterProxyModel with
setRecursiveFilteringEnabled(true);
create a folder hierachy under /home/yourusername/somefolder:
folder1
\-- foo
folder2
\-- bar
set the the filesystem model as source on the proxy model
set the the root path on the filesystemmodel to
/home/yourusername/somefolder
set the treeview root to the root item mapped to the proxymodel
Try set 'foo' as a filter in the QSFPM and see just
folder1
\-- foo
in the view
Try set 'home' as a filter in the QSFPM and see the full view expanded.
This seems to be because 'home' matches the 'home' in the path (because
setRootPath on QFileSystemModel doesn't change the model root node, but
just where the file gatherer is running; and also why you need to both
set the root path on the QFileSystemModel and the mapped index as the
root on the QTreeView)
Does anyone know a workaround or something else I have missed ?
I guess a SubtreeFilteringProxyModel could be what I'm looking for, but
didn't directly find it.
Any pointers anyone?
/Sune
More information about the Interest
mailing list