Results 1 to 4 of 4

Thread: QSortFilterProxyModel::filterAcceptsRow not being called

  1. #1
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt5

    Question QSortFilterProxyModel::filterAcceptsRow not being called

    Hello all!

    I basically have a source model that organizes the entries in a tree fashion in order to display it in a TreeView. Now I want to display the leaves of that tree source model in a TableView so I made a custom QSortFilterProxyModel that also works with filtering in order to display these entries properly. As far as I understand when I call the InvalidateFilter method it should invoke filterAcceptsRow but in this case it never gets called. Looking for a solution in the internet I found that apparently Qt won't invoke filterAcceptsRow if the parent of the index is not in the model (which I don't want it to be).

    Have you guys had a similar issue to this one and have a workaround that might work?

    Thanks a lot!

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortFilterProxyModel::filterAcceptsRow not being called

    What does 'is not in the model' mean? I don't see why a model should do something when an index for anything which is not in it's source model changes...

  3. #3
    Join Date
    Apr 2021
    Posts
    2
    Qt products
    Qt5

    Default Re: QSortFilterProxyModel::filterAcceptsRow not being called

    Quote Originally Posted by ChristianEhrlicher View Post
    What does 'is not in the model' mean? I don't see why a model should do something when an index for anything which is not in it's source model changes...
    Source Model
    Folder_1
    |->Item_1
    |->Item_2

    Folder_2
    |->Item_3
    |->Item_4


    ProxyModel
    Item_1
    Item_2
    Item_3
    Item_4

    So basically the parent indexes from the source model (Folder_1 and Folder_2) are not in the Proxy Model.
    I want to apply a filter to the proxy model, in the filterAcceptsRow method I check if the entry should be accepted in the model by checking if the entry matches the filter. Every time the filter changes I emit a filterChanged signal that will trigger a InvalidateFilter call that (in theory) will invoke that filterAcceptsRow method. The problem I have is that in this case filterAcceptsRow will never be called for some reason.
    Looking into other forums for people that had similar issues I came across this answer:
    I just understood that filterAcceptsRow get invoked only if parent of index is displayed in proxy model. Oherwise proxy model thinks that it is not worth to insert row in proxy model.
    So it is just how Qt handles that kind of situations.

    Hope this clarifies the issue.

    thanks!

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortFilterProxyModel::filterAcceptsRow not being called

    So the index is in the model and in the proxy model, it's just filtered out in the view.
    If you call invalidateFilter() then a new filtering will be started. Also you don't pass any model index to filterChanged() at all so I don't understand what you're trying to say.
    Please provide a *minimal* compilable example.

Similar Threads

  1. QSortFilterProxyModel lessThan is never called.
    By atomic in forum Qt Programming
    Replies: 8
    Last Post: 15th April 2015, 18:09
  2. QSortFilterProxyModel nothing changes
    By unix7777 in forum Qt Programming
    Replies: 7
    Last Post: 19th August 2012, 09:13
  3. filterAcceptsRow is not called.
    By kaushal_gaurav in forum Qt Programming
    Replies: 1
    Last Post: 10th February 2009, 09:05
  4. Optimizing filterAcceptsRow() to filter a tree
    By vfernandez in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2007, 13:50

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.