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 extended selection: shift problem
Forum Updated to NodeBB v4.3 + New Features

QListView extended selection: shift problem

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 2.5k Views 1 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.
  • J Offline
    J Offline
    JoseFernandez
    wrote on last edited by
    #1

    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!

    m.sueM 1 Reply Last reply
    0
    • J JoseFernandez

      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!

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi @JoseFernandez

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

      -Michael.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JoseFernandez
        wrote on last edited by
        #3

        Hi @m-sue

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

        Jose

        m.sueM 1 Reply Last reply
        0
        • J JoseFernandez

          Hi @m-sue

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

          Jose

          m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          2
          • J Offline
            J Offline
            JoseFernandez
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JoseFernandez
              wrote on last edited by
              #6

              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

              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