How can I set QFileSystemModel to display just directories?
Or is this impossible at all?
Asked
Active
Viewed 2,723 times
1

HostileFork says dont trust SE
- 32,904
- 11
- 98
- 167

user336635
- 2,081
- 6
- 24
- 30
2 Answers
7
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);

Andreas Haferburg
- 5,189
- 3
- 37
- 63

HostileFork says dont trust SE
- 32,904
- 11
- 98
- 167
-1
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);

fefe
- 3,342
- 2
- 23
- 45