1

I use this code.

 QFileSystemModel* fsModel = new QFileSystemModel(this);
 fsModel->setFilter(QDir::NoDotAndDotDot | QDir::Dirs );

I can not understand how to exclude some folders.

Jet
  • 528
  • 6
  • 17
  • 1
    you can use QFileSystemModel::setNameFilter - but that only allows inclusion rather than exclusion. Other than that you might be able to subclass QFileSystemModel to filter out certain directories – Jimmy Jul 12 '12 at 17:04

2 Answers2

2

Subclassing from a standard model is of course possible, but is considered bad style. You'll gain a nice reusable component by implementing a generic filter proxy model. Inherit from QAbstractProxyModel and implement a filter proxy.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
1

Create a filter model and use your QFileSystemModel as its source.

For your filter, QSortFilterProxyModel has most of what you need - you'll only have to provide a reimplementation of filterAcceptsRow to make the decision of which files should be passed through.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103