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. QFileSystemModel and QSortFilterProxyModel - root index is not preserved
Forum Updated to NodeBB v4.3 + New Features

QFileSystemModel and QSortFilterProxyModel - root index is not preserved

Scheduled Pinned Locked Moved Unsolved General and Desktop
c++qfilesystemmodeqsortfilterproxfiltering
25 Posts 8 Posters 6.8k Views 4 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.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 2 Jul 2019, 09:03 last edited by
    #16

    Hi
    nope, if i had made report, i would have linked url here :)
    So please do.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 2 Jul 2019, 09:15 last edited by
      #17

      I don't think it's a bug.
      setRootIndex is a method of the view. The model has no way of knowing (and shouldn't know) what a view is using as root. The filter set on the proxy applies to the whole model. If the index used as root by a view gets filtered out it's only natural for a view to revert to using QModelIndex() as root.

      What you need is a proxy model that implements the setRootIndex functionality at the model level. This is on the list of nice-things-I-would-like-to-add-to-Qt-models and it's a fairly easy one to do but I need to find time for it :(

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      5
      • M Offline
        M Offline
        MasterBLB
        wrote on 2 Jul 2019, 18:34 last edited by
        #18

        ...and now I'm confused :/

        J 1 Reply Last reply 2 Jul 2019, 18:41
        0
        • M MasterBLB
          2 Jul 2019, 18:34

          ...and now I'm confused :/

          J Offline
          J Offline
          JonB
          wrote on 2 Jul 2019, 18:41 last edited by
          #19

          @MasterBLB
          Confused in what way? I have just read this thread and what @VRonin has written seems correct to me. Are you not understanding what he is saying, or what?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MasterBLB
            wrote on 3 Jul 2019, 07:27 last edited by
            #20

            In the way such behavior breaks SOLID substitute rule - I can't use descendant class QFileSystemModel like it was its base class QAbstractItemModel in QSortFilterProxyModel. While not a 100% bug it's definitely a serious design flaw, and worth to be reported. But where?

            J V 2 Replies Last reply 3 Jul 2019, 08:01
            0
            • M MasterBLB
              3 Jul 2019, 07:27

              In the way such behavior breaks SOLID substitute rule - I can't use descendant class QFileSystemModel like it was its base class QAbstractItemModel in QSortFilterProxyModel. While not a 100% bug it's definitely a serious design flaw, and worth to be reported. But where?

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 3 Jul 2019, 08:01 last edited by
              #21

              @MasterBLB said in QFileSystemModel and QSortFilterProxyModel - root index is not preserved:

              But where?

              In Qt bug tracker https://bugreports.qt.io/secure/Dashboard.jspa
              Also you can talk to Qt developers on their mailing list.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • M MasterBLB
                3 Jul 2019, 07:27

                In the way such behavior breaks SOLID substitute rule - I can't use descendant class QFileSystemModel like it was its base class QAbstractItemModel in QSortFilterProxyModel. While not a 100% bug it's definitely a serious design flaw, and worth to be reported. But where?

                V Offline
                V Offline
                VRonin
                wrote on 3 Jul 2019, 08:44 last edited by VRonin 7 Mar 2019, 10:08
                #22

                breaks SOLID

                It doesn't. In fact, if it worked as you expected it would break SOLID

                it's definitely a serious design flaw

                Sorry to be brutal: No, it's not a flaw, you just didn't understand the design of model/views.
                To help you get a better idea of what is going on, try use the same model with 2 different treeviews. In only one of the view call setRootIndex, and then trigger the filtering.

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                2
                • B Offline
                  B Offline
                  Brad1111
                  wrote on 12 Feb 2025, 22:50 last edited by
                  #23

                  Im actually encountering the very same issue.
                  Clearly it wont be fixed by Qt since Ive even seen posts about this issue back from 2011.
                  Could someone help me a little bit by telling me what to do please ?

                  @VRonin You were the most precise, suggesting to implements the setRootIndex to the proxymodel, but I would still require a bit more info if I am to do it on my own please :D

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jeremy_k
                    wrote on 13 Feb 2025, 02:51 last edited by
                    #24

                    It looks like @VRonin implemented his idea. See https://github.com/VSRonin/QtModelUtilities/blob/master/READMERootIndexProxyModel.md

                    Asking a question about code? http://eel.is/iso-c++/testcase/

                    B 1 Reply Last reply 13 Feb 2025, 04:28
                    1
                    • J jeremy_k
                      13 Feb 2025, 02:51

                      It looks like @VRonin implemented his idea. See https://github.com/VSRonin/QtModelUtilities/blob/master/READMERootIndexProxyModel.md

                      B Offline
                      B Offline
                      Brad1111
                      wrote on 13 Feb 2025, 04:28 last edited by
                      #25

                      @jeremy_k Wow, Awesome ! Thanks for your answer and massive props to @VRonin !

                      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