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

QAbstractView::selectionCommand returning wrong value on MouseRelease in SingleSelection mode

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.6.0, 5.12.0, 5.12.1, 5.12.2, 5.12.3
    • Widgets: Itemviews
    • None
    • Windows

    Description

      There's an issue in QAbstractItemView::selectionCommand where if selectionMode is set to SingleSelection, releasing the mouse will always signal for no update. This presents a problem when an item is selected and wanting to deselect by clicking on empty space in the view since it'll never be deselected (NoUpdate). This goes against documentation which states "It is possible for the user to deselect the selected item.".

      Mouse release on empty space should in fact deselect the current item as it does in other SelectionModes.

      We currently had to work around this issue by overriding the mouseReleaseEvent on our view to cache the selection mode, switch to ExtendedSelection, call QAbstractItemView::mouseRelease... and then set selectionMode back to it's original state.

       

      Repro & sample code:

      // Repro steps:
      // - Select an item in the list
      // - Try to deselect by clicking on empty space
      // - Notice that items on single selection cannot be deselected
      // - Switch selection mode to ExtendedSelection and see required behavior when clicking on empty space
      QListView* pListView = new QListView();
      // Switch to extended selection to see required behavior
      pListView->setSelectionMode(QAbstractItemView::SingleSelection);
       
      // Use a ready-to-use model for a quick sample
      QFileSystemModel* pFileSystemModel = new QFileSystemModel();
      pFileSystemModel->setRootPath(QDir::currentPath());
      pListView->setModel(pFileSystemModel);
      

      Attachments

        1. main.cpp
          0.8 kB
        2. qt_bug.png
          qt_bug.png
          47 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            crytek_luis Luis Lairet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes