QListView extended selection: shift problem



  • Hi

    I have implemented a dialog with a QListView in it. I use the selectionChanged signal to update the selectionModel underlying it. However, I get unexpected behaviour when pressing the Shift key. To reproduce:

    1. Add 4 items to the list view
    2. Select the first item in the list (works fine, i.e. selects the item)
    3. Pressing Shift key, select all 4 items (works fine, i.e. selects all items)
    4. Still pressing Shift key, select the second item (no event is triggered! I expect first and second items to be selected)

    The behaviours for single selection and selection using the Control key both work as expected. Has anyone come across this problem before?

    Thanks!



  • Hi @JoseFernandez

    May you chose the wrong selcetionMode. It seems you would want to set to QAbstractItemView::ExtendedSelection

    -Michael.



  • Hi @m-sue

    Thanks for the reply - that's the selection mode that I have.

    Jose



  • Hi @JoseFernandez

    What you describe should work, is the expected behaviour of the shift key and normally works. I just tested it with one of my own ListWidgets (ListViews should not be different here).

    Maybe you inadvertantly used the CTRL key in between. This can disturb the normal working of the shift key up to a point where the shift key does no longer seem to work at all. Though this is probably not the case.

    Maybe you connected the model to the QListView and additionally did some selection transfer by yourself, something that the model already should do on its own (I suppose). And both actions interfer with each other.

    -Michael.



  • Hi @m-sue

    You are right, I do use the model selection to select items and possibly this is causing trouble. I have checked and yes, the QListView itself behaves normally as expected so it's not Qt's problem but mine. However, I need to use the model selection by design so I'll have to find a way to get similar behaviour using it :(

    Sorry for the bother.

    Jose



  • Hi again

    I think I know where the problem is. I was selecting the items one by one (from the model) instead of using QItemSelection as the widget does. Changing this seems to have solved the issue!

    Thanks for the chat - it helped me realise where the problem was :)

    Jose


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.