Results 1 to 5 of 5

Thread: QTreeView::problems with the filter

  1. #1
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt Jambi
    Platforms
    MacOS X Windows

    Default 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() ));
    Last edited by Mint87; 11th November 2011 at 15:21.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QTreeView::problems with the filter

    You may need to call
    Qt Code:
    1. setFilters( QDir::AllDirs | QDir::AllEntries );
    To copy to clipboard, switch view to plain text mode 
    on your model to ensure that it traverses into subdirectories and that the name filters are not applied to directory names.

  3. The following user says thank you to d_stranz for this useful post:

    Mint87 (15th November 2011)

  4. #3
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt Jambi
    Platforms
    MacOS X Windows

    Default 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.
    Last edited by Mint87; 15th November 2011 at 10:18. Reason: =)

  5. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

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

  6. #5
    Join Date
    Nov 2011
    Posts
    14
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4 Qt Jambi
    Platforms
    MacOS X Windows

    Default 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.
    Last edited by Mint87; 18th November 2011 at 12:14.

Similar Threads

  1. Replies: 2
    Last Post: 10th May 2010, 13:13
  2. Convolution filter
    By toutarrive in forum Qt Programming
    Replies: 5
    Last Post: 21st October 2009, 13:55
  3. Filter a table
    By Nefastious in forum Newbie
    Replies: 1
    Last Post: 18th September 2009, 10:45
  4. Problems with drawing image in paintEvent of QTreeView
    By Tito Serenti in forum Qt Programming
    Replies: 7
    Last Post: 24th December 2008, 23:25
  5. How to filter QSqlRelationalTable?
    By istdasklar in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2007, 17:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.