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. QListView extending selection changes currentIndex
Forum Updated to NodeBB v4.3 + New Features

QListView extending selection changes currentIndex

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 2.9k Views 2 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.
  • R Offline
    R Offline
    Rory_1
    wrote on last edited by
    #1

    In a QListView I want to prevent the currentIndex changing when the user extends a selection. I've looked at QAbstractItemView and QItemSelectionModel but do not see how to do this. Any help much appreciated.

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

      Hi,

      Seems to be something unlikely since you are indeed changing the current index to extend a selection.

      What are you trying to achieve ?

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

      R 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Seems to be something unlikely since you are indeed changing the current index to extend a selection.

        What are you trying to achieve ?

        R Offline
        R Offline
        Rory_1
        wrote on last edited by
        #3

        @SGaist I'm not clear on why I am changing the currentIndex when I extend a selection. My use case is an image viewer with a QListView holding thumbnails and a large view of the current index image. If a user extends the selection then the image changes to the last item in the extended selection.

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

          Which would be correct.

          From the looks of it you should rather work with the selectionChanged signal.

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

          R 1 Reply Last reply
          0
          • SGaistS SGaist

            Which would be correct.

            From the looks of it you should rather work with the selectionChanged signal.

            R Offline
            R Offline
            Rory_1
            wrote on last edited by
            #5

            @SGaist Actually I am using the selectionChanged signal. I guess I'll have to test whether the new selection still contains the displayed image and change the currentIndex back, using the previous in QItemSelectionModel::currentChanged.

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

              If you are using the selectionChanged signal, why would you need to modify current index ?

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

              R 1 Reply Last reply
              0
              • SGaistS SGaist

                If you are using the selectionChanged signal, why would you need to modify current index ?

                R Offline
                R Offline
                Rory_1
                wrote on last edited by
                #7

                @SGaist Maybe I should explain the use case again. The user has selected a thumbnail, the selection changes, the currentIndex is updated to the new thumbNail and the main image display gets updated to the new currentIndex. However, when the user extends the selection of thumbnails they do not want the current thumbnail to change. My entire app uses the currentIndex to display the main image, show the relevant metadata, filter and sort.

                None of this works if the currentIndex changes. Since extending a selection changes the currentIndex I need to recover it. I'm trying to think of a use case where it makes sense for the currentIndex to change with a selection extension.

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

                  Then why not keep track of the "selected index" and work with that one ? You'd be independent of the current index changes.

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

                  R 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Then why not keep track of the "selected index" and work with that one ? You'd be independent of the current index changes.

                    R Offline
                    R Offline
                    Rory_1
                    wrote on last edited by
                    #9

                    @SGaist I can do that. Thanks for the help.

                    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