Results 1 to 2 of 2

Thread: Hide parents in QSortFilterProxyModel if they don't match

  1. #1
    Join Date
    Feb 2010
    Russia, Omsk
    Qt products

    Default Hide parents in QSortFilterProxyModel if they don't match

    Hi. i have a treeview. What I need is to hide parents if they don't match but their child do. As I guess it leads to tree reconstruction - changing parent of visible children. How is it better to do it?
    Currently I have this, but of course it does show parents if children matches

    Qt Code:
    1. bool TreeFilteredModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
    2. {
    3. bool ret = false;
    4. QModelIndex subIndex = sourceModel()->index(sourceRow, 0, sourceParent);
    5. WorkflowTreeItem* item = (WorkflowTreeItem*)subIndex.internalPointer();
    6. int childCound = sourceModel()->rowCount(subIndex);
    7. if (subIndex.isValid())
    8. {
    9. for (int i = 0; i < childCound; ++i)
    10. {
    11. ret = ret || filterAcceptsRow(i, subIndex);
    12. }
    13. }
    14. ret |= (item->command()->getName().contains(m_commandSearchParameter, Qt::CaseInsensitive) && item->command()->getName().contains(m_textSearchParameter, Qt::CaseInsensitive));
    15. return ret;
    16. }
    To copy to clipboard, switch view to plain text mode 


  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default Re: Hide parents in QSortFilterProxyModel if they don't match

    As far as I remember filtering is done recursively, if you reject the parent, its children are not tested at all. So it seems your filtering boils down to checking if items match. If not, children will not be checked at all.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.

Similar Threads

  1. Multiple parents; not inheritance
    By tescrin in forum Qt Programming
    Replies: 15
    Last Post: 13th August 2012, 22:46
  2. Layout parents
    By qtnewbie500 in forum Newbie
    Replies: 1
    Last Post: 6th April 2012, 05:07
  3. How to access parents variables
    By revellix in forum Qt Programming
    Replies: 3
    Last Post: 10th October 2011, 16:03
  4. QStandardItemModel, parents and childs
    By alexandernst in forum Newbie
    Replies: 7
    Last Post: 23rd July 2009, 01:00

Tags for this Thread


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.