1

I would like to know how to hide a specific folder in a treeView with QFileSystemModel.

I know that we can filter folders to show only some files using setFilter but I don't know how to filter a folder.

I want to display folders except one. I know the name of this folder so I can choose it by the name.

Does anyone know how to hide/remove this folder from the list please?

Natan Streppel
  • 5,759
  • 6
  • 35
  • 43
Jeanstackamort
  • 309
  • 2
  • 4
  • 16
  • 1
    Did you try `QFileSystemModel::setNameFilters()`? – vahancho Jan 31 '14 at 15:50
  • Yes I already use QFileSystemModel::setNameFilters() to filter files by extension into a folder. So when I apply the filter I see only files with the extension I want. In my case I don't want to see a folder named "foldername". – Jeanstackamort Jan 31 '14 at 16:29

1 Answers1

3

The filters can use wildcards, but those wildcards are optional. You're free to use the filters to filter out a non-wildcard name.

QStringList filters;
filters << "*.badext" << "foldername";
model->setNameFilters(filters);

If you want tighter control over it - for example, to only filter out folder with a given name, and not a file with a given name, then you need to implement a QSortFilterProxyModel.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
  • Sorry for the late reply. Yes I want to filter out folder with a given name. So could you give me clues to implement this with a `QSortFilterProxyModel` please? I checked this class and I didn't find what I am looking for. – Jeanstackamort Feb 11 '14 at 17:46