Re: QTreeView::problems with the filter
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() ));
Re: QTreeView::problems with the filter
You may need to call
Code:
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.
Re: QTreeView::problems with the filter
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.
Re: QTreeView::problems with the filter
Have you bothered to read the QDir documentation at all? There is another QDir flag specifically for that purpose.
Re: QTreeView::problems with the filter
Yeap, it was really easy. But I'm doing a lot simultaneously and I'm really a very beginner and I DID read it.