Results 1 to 4 of 4

Thread: QFileSystemModel and QSortFilterProxyModel don't work well together?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileSystemModel and QSortFilterProxyModel don't work well together?

    this code only filter the file who name is EXACTLY ".cpp", line 12 and 13
    Qt Code:
    1. sfpm->setFilterRegExp(QRegExp(".cpp", Qt::CaseInsensitive,QRegExp::FixedString));
    To copy to clipboard, switch view to plain text mode 

    this code filter all the file who suffix are "cpp",
    Qt Code:
    1. sfpm->setFilterRegExp(QRegExp("*.cpp", Qt::CaseInsensitive,QRegExp::WildcardUnix));
    To copy to clipboard, switch view to plain text mode 

    that can rewrite like ...
    Qt Code:
    1. sfpm->setFilterCaseSensitivity(Qt::CaseInsensitive);
    2. sfpm->setFilterWildcard ("*.cpp");
    To copy to clipboard, switch view to plain text mode 
    Last edited by ecanela; 21st August 2012 at 23:05. Reason: spelling corrections

  2. #2

    Wink Re: QFileSystemModel and QSortFilterProxyModel don't work well together?

    Thanks, All. But I think spirit is basic right. It has nothing to do with if the RegExp is correct. The real problem is hierarchical data model. I need to subclass QSortFilterProxyModel to do something concerning "source_parent":

    Qt Code:
    1. class MySortFilterProxyModel : public QSortFilterProxyModel
    2. {
    3. protected:
    4. virtual bool MySortFilterProxyModel::filterAcceptsRow(
    5. int source_row, const QModelIndex &source_parent) const{
    6. QFileSystemModel *sm = qobject_cast<QFileSystemModel*>(sourceModel());
    7. if (source_parent == sm->index(sm->rootPath())) {
    8. return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
    9. }
    10. return true;
    11. }
    12. };
    To copy to clipboard, switch view to plain text mode 
    This works fine for me.

Similar Threads

  1. Replies: 0
    Last Post: 9th March 2011, 00:08
  2. Help with QFileSystemModel
    By TheShow in forum Qt Programming
    Replies: 4
    Last Post: 5th January 2010, 20:11
  3. Replies: 12
    Last Post: 5th July 2009, 16:03
  4. Replies: 6
    Last Post: 3rd November 2006, 11:53

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.