Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120272

QTableview range selection using shift+click changed after 1 pixel move

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.2.4, 6.3, 6.4, 6.5, 6.6
    • Widgets: Itemviews
    • None
    • macOS, Windows

    Description

      Selecting items using Shift key is very hard. The selection is lost after clicking the last item while pressing shift key. It's very annoying. It looks like it's a regression from previous versions. It was supposed to be fixed. See this bug :  https://bugreports.qt.io/browse/QTBUG-81542

       

      The issue appeared in Qt 6.2.4 and is still present in Qt 6.6. It worked well in Qt 6.2.3.

      I attached a video showing the issue in Qt 6.2.3, 6.2.4 and Qt 6.6.0. I'm holding shift key to select multiple items.

       

      I also attached the sample project based on relationaltablemodel sample.

       

      I've just added these lines in relationaltablemodel sample :

      // Code added to reproduce the bug
      view->setSelectionMode(QAbstractItemView::ExtendedSelection);
      view->setDragEnabled(true);
      // end of added code

       

      For those having trouble with this bug, I've found this workaround that seems to work well:

      void InheritedTableView::mousePressEvent(QMouseEvent *event)
      {
      
      #if (QT_VERSION >= QT_VERSION_CHECK(6, 2, 4))
          // workaround for selection bug using shift key in Qt 6.2.4 and above (no bug in Qt 6.2.3):
          // when the mouse moves 1 pixel when making a range selection (shift + left-mouse-button), the selection resets to just the last item clicked.
          // see https://bugreports.qt.io/browse/QTBUG-120272 
      
         if (event->modifiers() & Qt::ShiftModifier)
         {
              bool isDragEnabled = dragEnabled();
              setDragEnabled(false);
              QTableView::mousePressEvent(event);
              setDragEnabled(isDragEnabled);
              return;
         }
      #endif   
      
          QTableView::mousePressEvent(event); 
      
      }
      

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              vhilshei Volker Hilsheimer
              maxime maxime
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes