2

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?

lvp
  • 2,078
  • 18
  • 24

2 Answers2

1

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
filters.append("*.h");

QFileSystemModel *model = new QFileSystemModel;
model->setNameFilters(filters);

QTreeView *view = new QTreeView;
view->setModel(model);
Daniel Gallagher
  • 6,915
  • 25
  • 31
  • 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 00: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 00:53
0
//filter treeview for directories and torrent files only

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

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

model->setNameFilters(filters);
ui->treeView->setModel(model);