Reputation: 2291
How can I set QFileSystemModel to display just directories?
Or is this impossible at all?
Upvotes: 1
Views: 2952
Reputation: 33607
Have never had a chance to use the QFileSystemModel myself, but looking at the docs...did you try setFilter()?
http://doc.qt.io/qt-5/qfilesystemmodel.html#setFilter
http://doc.qt.io/qt-5/qdir.html#Filter-enum
The documentation notes, the default filter is QDir::AllEntries | QDir::NoDotAndDotDot | QDir::AllDirs
. That expands to: QDir::Dirs | QDir::Files | QDir::Drives | QDir::NoDotAndDot | QDir::AllDirs
, and it says AllDirs is required.
So maybe just:
model->setFilter(QDir::Dirs|QDir::Drives|QDir::NoDotAndDotDot|QDir::AllDirs);
Upvotes: 7
Reputation: 3442
In one working project in my hand, another approach (not QFileSystemModel
) is taken to display only directories:
QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
options |= QFileDialog::DontUseNativeDialog;
QString directory = QFileDialog::getExistingDirectory(this,
tr("Select the data path"),
"",
options);
Upvotes: -1