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

QItemSelectionModel clear selection when selected index column is > 0

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.8.0
    • Widgets: Itemviews
    • None
    • be0a221ae491b8426b3a4cdf0d5863701e922c1f

    Description

      Description
      --------------
      The QItemSelection lose its selection if it contains a selected index whose column is > 0 (i.e. index(0,1) and the QItemSelection::Model emits the layoutChanged signal.

      How to reproduce
      -----------------------
      1) Create a project with a TableModel and a QTableView
      2) Enable QTableView sorting
      3) Select index(0,1) in the view
      4) Sort the indexes by first column
      5) The selection is lost but the current index remains

      Debug Session
      ----------------------
      This is caused by line
      https://code.woboq.org/qt5/qtbase/src/corelib/itemmodels/qitemselectionmodel.cpp.html#926

      result.append(QItemSelectionRange(tl, br.sibling(br.row(), length - 1)));
      

      In fact:

      • tl is index(0,1)
      • br is index(0,1) too given that we selected a single index
      • length is 1

      but that range is invalid because the QItemSelectionRange is

      {index(0,1), index(0,0)}

      and the TopLeft.left() is > BottomRight.right()

      Attachments

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

        Activity

          People

            mmutz Marc Mutz
            cuke Filippo Cucchetto
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes