Qt: QFileSystemModel Filter Out Directories (not files) by expression

1.5k views Asked by At

How can i filter out Folders? I looked for QDir::Filters here: but i cannot see how to filter by expression. I Want to Hide Folders Starting with "A00*"

enter image description here

I tried to use nameFilters, but then the folders are just becoming grey:

QStringList filters;
filters <<"Cloth";
dirModel->setNameFilters(filters);

enter image description here

1

There are 1 answers

3
vahancho On BEST ANSWER

There is a QFileSystemModel's property that defines how items (files, directories) should be visualized is they do not pass the name filter. It is nameFilterDisables. By default this property is true, i.e. items that do not pass the name filter are disabled. For your case you have to disable this property to make non filtered items hidden:

dirModel->setNameFilterDisables(false);