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. Move items in a QSortFilterProxyModel
Forum Updated to NodeBB v4.3 + New Features

Move items in a QSortFilterProxyModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 4 Posters 4.8k Views
  • 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.
  • V Valerian

    @JonB said in Move items in a QSortFilterProxyModel:

    he important thing is my second point, the return result of beginMoveRows() with whatever parameters you give it. Your debug shows it returned false. So long as it returns false in your case, it's not going to work, and you need to figure why not!

    I reverted the code and it returns true but the row isn't actually shifted

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

    @Valerian
    Fair enough. Then I can only suggest you read that doc page carefully to understand what they are saying is required in each direction, and play with the parameters/which row/how far you move the row till you see something happening, and figure from there.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #9
      • moveRow must already call beginMoveRows and endMoveRows inside itself so you are duplicating calls
      • moveRow is not implemented in any of Qt's model (as far as I'm aware) so it will probably just do nothing and return false (check the return value)

      What model are you using as source to this proxy?

      "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

      V JonBJ 2 Replies Last reply
      2
      • VRoninV VRonin
        • moveRow must already call beginMoveRows and endMoveRows inside itself so you are duplicating calls
        • moveRow is not implemented in any of Qt's model (as far as I'm aware) so it will probably just do nothing and return false (check the return value)

        What model are you using as source to this proxy?

        V Offline
        V Offline
        Valerian
        wrote on last edited by
        #10

        @VRonin said in Move items in a QSortFilterProxyModel:

        What model are you using as source to this proxy?

        QAbstractTableModel

        VRoninV 1 Reply Last reply
        0
        • VRoninV VRonin
          • moveRow must already call beginMoveRows and endMoveRows inside itself so you are duplicating calls
          • moveRow is not implemented in any of Qt's model (as far as I'm aware) so it will probably just do nothing and return false (check the return value)

          What model are you using as source to this proxy?

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

          @VRonin
          Don't forget OP is claiming that one of his moveUp/moveDown does work, while the other does not....

          moveRow must already call beginMoveRows and endMoveRows inside itself so you are duplicating calls

          If that's true that might explain....!

          1 Reply Last reply
          0
          • V Valerian

            @VRonin said in Move items in a QSortFilterProxyModel:

            What model are you using as source to this proxy?

            QAbstractTableModel

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #12

            @Valerian said in Move items in a QSortFilterProxyModel:

            QAbstractTableModel

            Did you reimplement moveRow?

            "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

            V VRoninV 2 Replies Last reply
            0
            • VRoninV VRonin

              @Valerian said in Move items in a QSortFilterProxyModel:

              QAbstractTableModel

              Did you reimplement moveRow?

              V Offline
              V Offline
              Valerian
              wrote on last edited by
              #13

              @VRonin I re-implemeted it in the QSortFilterProxyModel. Didn't want to move rows in the main model

              JonBJ 1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #14

                Can you post the implementation?

                "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

                V 1 Reply Last reply
                0
                • V Valerian

                  @VRonin I re-implemeted it in the QSortFilterProxyModel. Didn't want to move rows in the main model

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

                  @Valerian
                  I now realise you got your code from https://stackoverflow.com/a/43683619/489865, didn't you? Wasn't actually confirmed to be correct solution. I still don't get where the + 2 comes from, but there you are.

                  IF @VRonin does not sort you out (so to speak :) ), I don't know, but maybe you should have a careful read of https://stackoverflow.com/a/12254935/489865. Not sure whether the following might affect you:

                  (2) Yes if you don't use sorting, just filtering. Qt in such case erases entire internal mapping and re-builds it from scratch so the data will be just as they appear in source model

                  V 1 Reply Last reply
                  0
                  • VRoninV VRonin

                    Can you post the implementation?

                    V Offline
                    V Offline
                    Valerian
                    wrote on last edited by
                    #16

                    @VRonin said in Move items in a QSortFilterProxyModel:

                    Can you post the implementation?

                    I have already posted the implementation of the QSortFilterProxyModel. Are you seeking the implementation of the QAbstractTableModel?

                    VRoninV 1 Reply Last reply
                    0
                    • V Valerian

                      @VRonin said in Move items in a QSortFilterProxyModel:

                      Can you post the implementation?

                      I have already posted the implementation of the QSortFilterProxyModel. Are you seeking the implementation of the QAbstractTableModel?

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #17

                      @VRonin said in Move items in a QSortFilterProxyModel:

                      Did you reimplement moveRow?

                      @Valerian said in Move items in a QSortFilterProxyModel:

                      I re-implemeted it in the QSortFilterProxyModel.

                      I don't see an implementation of FilterProxyModel::moveRow (or rather FilterProxyModel::moveRows) above

                      "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

                      V 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @Valerian
                        I now realise you got your code from https://stackoverflow.com/a/43683619/489865, didn't you? Wasn't actually confirmed to be correct solution. I still don't get where the + 2 comes from, but there you are.

                        IF @VRonin does not sort you out (so to speak :) ), I don't know, but maybe you should have a careful read of https://stackoverflow.com/a/12254935/489865. Not sure whether the following might affect you:

                        (2) Yes if you don't use sorting, just filtering. Qt in such case erases entire internal mapping and re-builds it from scratch so the data will be just as they appear in source model

                        V Offline
                        V Offline
                        Valerian
                        wrote on last edited by
                        #18

                        @JonB said in Move items in a QSortFilterProxyModel:

                        I now realise you got your code from https://stackoverflow.com/a/43683619/489865, didn't you? Wasn't actually confirmed to be correct solution. I still don't get where the + 2 comes from, but there you are.

                        Yes I did pick it from there.

                        Thanks for the other stackflow link. Will have a read on that.

                        1 Reply Last reply
                        0
                        • VRoninV VRonin

                          @VRonin said in Move items in a QSortFilterProxyModel:

                          Did you reimplement moveRow?

                          @Valerian said in Move items in a QSortFilterProxyModel:

                          I re-implemeted it in the QSortFilterProxyModel.

                          I don't see an implementation of FilterProxyModel::moveRow (or rather FilterProxyModel::moveRows) above

                          V Offline
                          V Offline
                          Valerian
                          wrote on last edited by
                          #19

                          @VRonin said in Move items in a QSortFilterProxyModel:

                          I don't see an implementation of FilterProxyModel::moveRow (or rather FilterProxyModel::moveRows) above

                          I haven't implement that. Not sure if I need to write that

                          1 Reply Last reply
                          0
                          • VRoninV VRonin

                            @Valerian said in Move items in a QSortFilterProxyModel:

                            QAbstractTableModel

                            Did you reimplement moveRow?

                            VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by
                            #20

                            @VRonin said in Move items in a QSortFilterProxyModel:

                            Did you reimplement moveRow?

                            @Valerian said in Move items in a QSortFilterProxyModel:

                            I re-implemeted it in the QSortFilterProxyModel

                            You lied to me!

                            As I mentioned, the default implementation does nothing and returns false so calling it is pointless unless you reimplement 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

                            JonBJ 1 Reply Last reply
                            1
                            • VRoninV VRonin

                              @VRonin said in Move items in a QSortFilterProxyModel:

                              Did you reimplement moveRow?

                              @Valerian said in Move items in a QSortFilterProxyModel:

                              I re-implemeted it in the QSortFilterProxyModel

                              You lied to me!

                              As I mentioned, the default implementation does nothing and returns false so calling it is pointless unless you reimplement it

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

                              @VRonin [I don't get what's happening in the pic? :( ]

                              VRoninV 1 Reply Last reply
                              0
                              • JonBJ JonB

                                @VRonin [I don't get what's happening in the pic? :( ]

                                VRoninV Offline
                                VRoninV Offline
                                VRonin
                                wrote on last edited by
                                #22

                                @JonB https://www.youtube.com/watch?v=xXdD9yFZGv8

                                "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

                                JonBJ 1 Reply Last reply
                                0
                                • VRoninV VRonin

                                  @JonB https://www.youtube.com/watch?v=xXdD9yFZGv8

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

                                  @VRonin
                                  Dear Mr VRonin,

                                  Thank you for that link. I opened it from Firefox from the Ubuntu I sit inside as a VirtualBox under Windows Server.

                                  The video started, and then froze. My whole Linux guest box froze. Nothing other than a Windows TaskMan kill of the whole VBox was possible, killing my session and any work I had done but not committed!

                                  Please remind me never to risk clicking on such a link again! :) I shall have to manage without knowing the meaning of the pic now...

                                  VRoninV 1 Reply Last reply
                                  1
                                  • JonBJ JonB

                                    @VRonin
                                    Dear Mr VRonin,

                                    Thank you for that link. I opened it from Firefox from the Ubuntu I sit inside as a VirtualBox under Windows Server.

                                    The video started, and then froze. My whole Linux guest box froze. Nothing other than a Windows TaskMan kill of the whole VBox was possible, killing my session and any work I had done but not committed!

                                    Please remind me never to risk clicking on such a link again! :) I shall have to manage without knowing the meaning of the pic now...

                                    VRoninV Offline
                                    VRoninV Offline
                                    VRonin
                                    wrote on last edited by
                                    #24

                                    @JonB Sorry mate, it was just a stupid YouTube video of a guy saying carrots are good for eyesight, another guy shoving 2 carrots in his eyes and then the image above

                                    "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

                                    V JonBJ 2 Replies Last reply
                                    3
                                    • VRoninV VRonin

                                      @JonB Sorry mate, it was just a stupid YouTube video of a guy saying carrots are good for eyesight, another guy shoving 2 carrots in his eyes and then the image above

                                      V Offline
                                      V Offline
                                      Valerian
                                      wrote on last edited by
                                      #25

                                      @VRonin Thank you for your feedback. Will re-implement those functions and try

                                      1 Reply Last reply
                                      0
                                      • VRoninV VRonin

                                        @JonB Sorry mate, it was just a stupid YouTube video of a guy saying carrots are good for eyesight, another guy shoving 2 carrots in his eyes and then the image above

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

                                        @VRonin Ohhhhh, I would never have figured that's what it was! All OK :)

                                        1 Reply Last reply
                                        1
                                        • F Offline
                                          F Offline
                                          fanyha
                                          wrote on last edited by
                                          #27

                                          hi, can anybody tell me how to implement moveRows() for the class derived from QSortFilterProxyModel:
                                          moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)

                                          it looks like we need to exchange the proxy indexes, but we can't access to the private members in the subclass

                                          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