Using a QTreeView and a QListView, I want to show only usable files for a certain software.
the QTreeview shows folders only and QListView show the files in folders :
self.treeview = QtWidgets.QTreeView()
self.listview = QtWidgets.QListView()
self.dirModel = QtWidgets.QFileSystemModel()
self.dirModel.setRootPath(QtCore.QDir.rootPath())
self.dirModel.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.AllDirs)
self.dirModel.setFilter()
self.fileModel = QtWidgets.QFileSystemModel()
self.fileModel.setFilter(QtCore.QDir.NoDotAndDotDot | QtCore.QDir.Files)
the QListView is filtered to show only .gfr files with
self.fileModel.setNameFilters(['*.gfr'])
it works as expected, but the treeview now shows many folders without content.
my question is : how can I hide automatically folders shows as empty due to filtering ?
EDIT : The goal of it is to offer the user only folders where he/she can find usable files and avoid random search in different folders. when the user found the needed file, it double click it to open with the software
folders structures are the following, capitals name are fixed :
root
|__assetType1 (changing name, 5 possible names )
|__asset1 (changing name, from 1 to around 50 possible names)
|__WORK(fixed name for all assets )
|__SHD(fixed name - contain the wanted gfr files when they exist)
|__TEX (fixed name, 5 possible names, all needs to be hidden except 'SHD' )
|__PUBLISH (fixed name - needs to be hidden )
the goal is to hide 'asset' folder and all subfolders from TreeView if no '.gfr' files are found in it's WORK/SHD subdirectory