View Full Version : QTreeView::problems with the filter

11th November 2011, 16:21
Hello, I have a problem here.

I need to filter my QTreeView with certain file criteria.
So far I have this:

QDirModel * TreeModel = new QDirModel;
TempTreeView->setModel( TreeModel );
QDir dir(SourceWidget->getPath() );

How can I display only .h and .cpp files in my QTreeView?

Thank you.

Added after 1:

I did filter, but it filters in a strange way. Only these cpp and .h files are shown which are in top level folder. So now the problem is how to make visible the content of subfolders.

QDirModel * TreeModel = new QDirModel;
TempTreeView->setModel( TreeModel );

QStringList filters;
filters << "*.cpp" << "*.h";

TempTreeView->setRootIndex(TreeModel->index( SourceWidget->getPath() ));

12th November 2011, 00:46
You may need to call
setFilters( QDir::AllDirs | QDir::AllEntries ); on your model to ensure that it traverses into subdirectories and that the name filters are not applied to directory names.

15th November 2011, 11:15
Thanks a lot!
It worked in principal but it shows sub directories with ''..'', ''.'' .
Can you give me some advices how can I get rid of it?
Thank you.

15th November 2011, 22:21
Have you bothered to read the QDir documentation at all? There is another QDir flag specifically for that purpose.

18th November 2011, 13:03
Yeap, it was really easy. But I'm doing a lot simultaneously and I'm really a very beginner and I DID read it.