Solved QListView extending selection changes currentIndex
-
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.
-
Hi,
Seems to be something unlikely since you are indeed changing the current index to extend a selection.
What are you trying to achieve ?
-
@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.
-
Which would be correct.
From the looks of it you should rather work with the selectionChanged signal.
-
@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.
-
If you are using the selectionChanged signal, why would you need to modify current index ?
-
@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.
-
Then why not keep track of the "selected index" and work with that one ? You'd be independent of the current index changes.
-
@SGaist I can do that. Thanks for the help.