Take the 2-minute tour ×

Is it possible to set only one file format visible to the user? I'm searching it in documentation, but I can't find it... If not, which other widget you are suggesting to use?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

I assume you're using a QTreeView with a QFileSystemModel. If not, I'd suggest doing so. QTreeWidget is not as flexible.

QFileSystemModel has a method called setNameFilters that should do what you want. To use it, do something like this:

QStringList filters;
filters.append("*.cc"); // whatever filters you want

QFileSystemModel *model = new QFileSystemModel;

QTreeView *view = new QTreeView;
share|improve this answer
Thanks! I tried it, but I can see only...C directory and then 1 child catalog, and then 1 grand-child and that's all. I would try it for another time, but I don't have much and, and for my projects useful will be QFileDialog used as widget inside the MainWindow because it has filesSelected() signal. (The goal is to select file and send the QString to funtions that plays the music). But after I select the QFileDialog dissapears. Do you know how to set it for never dissaper? –  lvp Jan 18 '11 at 0:24
I don't think you can make the standard QFileDialog never close without re-writing (sub-classing) it. You could watch for when it's finished and re-show it immediately, but that will probably result in some flicker. You can get a QItemSelectionModel from a QFileSystemModel to tell when a selection has changed (and what the selection is). It will be more work, but I think you will be more satisfied with the result if you can get the QFileSystemModel to behave. –  Daniel Gallagher Jan 18 '11 at 0:53
//filter treeview for directories and torrent files only

QStringList filters;
filters << "*.torrent";

QDirModel model = new QDirModel(this);
model->setSorting(QDir::DirsFirst |QDir::IgnoreCase | QDir::Type);
model->setFilter(QDir::AllDirs | QDir::AllEntries |QDir::NoDotAndDotDot);

share|improve this answer
please add some explanation to your answer. –  imsiso Apr 17 '13 at 21:05

Your Answer


