QsortFilterProxyModel filter parents without visible children.
-
Hi
I am trying to filter parents whose children are all filtered.
I can do it by looping through children when
filterAcceptsRow
is called on the parent, but I thought there would be a better way.I could connect to a signal
rowFiltered(row_source, source_parent)
and find parents filtered rows to check the condition, but there are no signal for filtering and no way to get filtered rows (or columns).
Is there a reason for that ?Plus, I would need to invalidate the row filter for the specific parent, but currently I can only invalidate all filters.
Is there another way to do it ? (I thought ofview.udpate(index)
but it did not seems to work.Thank you.
-
Hi and welcome to devnet,
I am not sure to follow you properly. What do you mean by "filter the parents" ? Reapply your filtering logic on them ? Ignore them ? Something else ?
-
Hi and welcome to devnet,
I am not sure to follow you properly. What do you mean by "filter the parents" ? Reapply your filtering logic on them ? Ignore them ? Something else ?
@SGaist said in QsortFilterProxyModel filter parents without visible children.:
I am not sure to follow you properly. What do you mean by "filter the parents" ? Reapply your filtering logic on them ? Ignore them ? Something else ?
I suspect/guess the OP means: There is a filter. Initially parents ignore that, so that the filter can be applied to all children. Then if all children get filtered out, so that no children are left which pass the filter, then filter out the parent, so you do not get left with an "empty" parent node.
I do not know what the OP wants relative to the long discussion in the old thread referenced. Since that is quite big it needs careful study and I do not know whether the OP has any problem with what is there. Nor do i know what the OP's latest "I could call filterAcceptsRow but it would not mean a thing for the view" means.
-
Maybe it's worth looking at https://doc.qt.io/qt-6/qsortfilterproxymodel.html#recursiveFilteringEnabled-prop
-
Maybe it's worth looking at https://doc.qt.io/qt-6/qsortfilterproxymodel.html#recursiveFilteringEnabled-prop
@Christian-Ehrlicher
The OP should certainly be using that. And I do not know whether the introduction of that property precedes the old thread from 2011.I thought that property simply allowed children to be investigated without rejecting the parent for failing the filter in the first place. I did not think it removed the parent if all children failed the filter. But I see the docs state:
This property holds whether the filter to be applied recursively on children, and for any matching child, its parents will be visible as well.
Maybe that does imply that if no children are visible the parent will be suppressed too, and so on recursively up the tree? But if it does it may indeed be just what the OP is wanting.
-
@Christian-Ehrlicher
The OP should certainly be using that. And I do not know whether the introduction of that property precedes the old thread from 2011.I thought that property simply allowed children to be investigated without rejecting the parent for failing the filter in the first place. I did not think it removed the parent if all children failed the filter. But I see the docs state:
This property holds whether the filter to be applied recursively on children, and for any matching child, its parents will be visible as well.
Maybe that does imply that if no children are visible the parent will be suppressed too, and so on recursively up the tree? But if it does it may indeed be just what the OP is wanting.
@JonB said in QsortFilterProxyModel filter parents without visible children.:
And I do not know whether the introduction of that property precedes the old thread from 2011.
It's from 2017: https://codereview.qt-project.org/c/qt/qtbase/+/151000
-
I suspect/guess the OP means: There is a filter. Initially parents ignore that, so that the filter can be applied to all children. Then if all children get filtered out, so that no children are left which pass the filter, then filter out the parent, so you do not get left with an "empty" parent node.
I do not know what the OP wants relative to the long discussion in the old thread referenced. Since that is quite big it needs careful study and I do not know whether the OP has any problem with what is there. Nor do i know what the OP's latest "I could call filterAcceptsRow but it would not mean a thing for the view" means.
Yes, this is what I meant. Sorry if it was not clear enough.
Nor do i know what the OP's latest "I could call filterAcceptsRow but it would not mean a thing for the view" means.
It means that I want the view to trigger a filter on a given index. Like it would be if you would call
invalidate
.Maybe that does imply that if no children are visible the parent will be suppressed too, and so on recursively up the tree? But if it does it may indeed be just what the OP is wanting.
Unfortunatly no, setting recursive filtering to True means that if the parent is filtered out but not the children, the parent will be visible.
-
I suspect/guess the OP means: There is a filter. Initially parents ignore that, so that the filter can be applied to all children. Then if all children get filtered out, so that no children are left which pass the filter, then filter out the parent, so you do not get left with an "empty" parent node.
I do not know what the OP wants relative to the long discussion in the old thread referenced. Since that is quite big it needs careful study and I do not know whether the OP has any problem with what is there. Nor do i know what the OP's latest "I could call filterAcceptsRow but it would not mean a thing for the view" means.
Yes, this is what I meant. Sorry if it was not clear enough.
Nor do i know what the OP's latest "I could call filterAcceptsRow but it would not mean a thing for the view" means.
It means that I want the view to trigger a filter on a given index. Like it would be if you would call
invalidate
.Maybe that does imply that if no children are visible the parent will be suppressed too, and so on recursively up the tree? But if it does it may indeed be just what the OP is wanting.
Unfortunatly no, setting recursive filtering to True means that if the parent is filtered out but not the children, the parent will be visible.
@pchar2 said in QsortFilterProxyModel filter parents without visible children.:
Unfortunatly no, setting recursive filtering to True means that if the parent is filtered out but not the children, the parent will be visible.
I thought that might be the case hence did not suggest it. Though you should definitely be passing that flag for your case anyway. I didn't read through it all but isn't the thread you referenced about as detailed as it gets for your issue?
-
@pchar2 said in QsortFilterProxyModel filter parents without visible children.:
Unfortunatly no, setting recursive filtering to True means that if the parent is filtered out but not the children, the parent will be visible.
I thought that might be the case hence did not suggest it. Though you should definitely be passing that flag for your case anyway. I didn't read through it all but isn't the thread you referenced about as detailed as it gets for your issue?
@JonB said in QsortFilterProxyModel filter parents without visible children.:
Though you should definitely be passing that flag for your case anyway
Why ?
I didn't read through it all but isn't the thread you referenced about as detailed as it gets for your issue?
The thing is, I am using lazy loading. So when I'm filtering an index, I do not know all of its children, and would prefer not to call a
fetchMore
right away.The problem was stated here but not answered.
Can I make a suggestion somewhere, that
recursiveFiltering
should check if all children of a parent are filtered and if so filter the parent ? -
@JonB said in QsortFilterProxyModel filter parents without visible children.:
Though you should definitely be passing that flag for your case anyway
Why ?
I didn't read through it all but isn't the thread you referenced about as detailed as it gets for your issue?
The thing is, I am using lazy loading. So when I'm filtering an index, I do not know all of its children, and would prefer not to call a
fetchMore
right away.The problem was stated here but not answered.
Can I make a suggestion somewhere, that
recursiveFiltering
should check if all children of a parent are filtered and if so filter the parent ?@pchar2
Because I would have thought you want that flag for the default case, where filter letting a child through would allow the parent to be displayed. As per https://www.kdab.com/new-qt-5-10-recursive-filtering-qsortfilterproxymodel/.Suggestions go to https://bugreports.qt.io/.
-
Because I would have thought you want that flag for the default case
Ah, thank you, but in this specific case I would have wanted another type of recursion to happen : )
Suggestions go to https://bugreports.qt.io/.
Thank you, I will try to provide as much info as possible and post the link here when it's done.