Results 1 to 2 of 2

Thread: How to make QSortFilterProxyModel search through children in a treeWidget?

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to make QSortFilterProxyModel search through children in a treeWidget?

    Hey all,
    I´m using a QSortFilterProxyModel to search through my QtreeWidget like this:
    Qt Code:
    1. QAbstractItemModel * sourceModel;
    2. sourceModel = ui.treeWidget->model();
    3. proxyModel->setSourceModel(sourceModel);
    4. ui.treeWidget->QtreeWidget::setModel(proxyModel);
    5. proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,QRegExp::FixedString));
    To copy to clipboard, switch view to plain text mode 
    The problem is that as the documentation says:
    "For hierarchical models, the filter is applied recursively to all
    children. If a parent item doesn't match the filter, none of its
    children will be shown."
    I would like all parent items to be shown as long as one of their
    children match the filter or of course if the parent itself matches
    the filter. Kind of like how the collection tab in amarok works. Any
    idea how could I do that?

    thanx in advance

    Pat

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to make QSortFilterProxyModel search through children in a treeWidget?

    Reimplement either the sort proxy model or the abstract one and implement the functionality yourself. You'll probably want to cache the results as you have to be searching bottom-up and not top-down and it is more time consuming.

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.