Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QsortFilterProxyModel filter parents without visible children.
Forum Updated to NodeBB v4.3 + New Features

QsortFilterProxyModel filter parents without visible children.

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 354 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pchar2
    wrote on last edited by pchar2
    #1

    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 of view.udpate(index) but it did not seems to work.

    Thank you.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      JonBJ 1 Reply Last reply
      0
      • P Offline
        P Offline
        pchar2
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Hello, thank you : )

        Reapply your filtering logic on them ?

        Yes. As discussed in this old thread .

        I could call filterAcceptsRow but it would not mean a thing for the view.

        1 Reply Last reply
        0
        • SGaistS SGaist

          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 ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Maybe it's worth looking at https://doc.qt.io/qt-6/qsortfilterproxymodel.html#recursiveFilteringEnabled-prop

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            JonBJ 1 Reply Last reply
            1
            • Christian EhrlicherC Christian Ehrlicher

              Maybe it's worth looking at https://doc.qt.io/qt-6/qsortfilterproxymodel.html#recursiveFilteringEnabled-prop

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @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 EhrlicherC 1 Reply Last reply
              0
              • JonBJ JonB

                @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 EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  pchar2
                  wrote on last edited by
                  #8

                  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.

                  JonBJ 1 Reply Last reply
                  0
                  • P pchar2

                    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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @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?

                    P 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @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?

                      P Offline
                      P Offline
                      pchar2
                      wrote on last edited by
                      #10

                      @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 ?

                      JonBJ 1 Reply Last reply
                      0
                      • P pchar2

                        @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 ?

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @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/.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          pchar2
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved