PDA

View Full Version : QTreeView::problems with the filter



Mint87
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() );
TempTreeView->setRootIndex(TreeModel->index(dir.path()));

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;
TreeModel->setReadOnly(false);
TempTreeView->setModel( TreeModel );

QStringList filters;
filters << "*.cpp" << "*.h";
TreeModel->setNameFilters(filters);

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

d_stranz
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.

Mint87
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.

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

Mint87
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.