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

Behavior of selectionChanged() on removing first of two rows

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.9.0
    • Widgets: Itemviews
    • None

    Description

      Please run the following code:

      QTableWidget* tableWidget = new QTableWidget(2, 2, nullptr);
      tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
      tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
      connect(tableWidget->selectionModel(), &QItemSelectionModel::selectionChanged, 
         [&](const QItemSelection& selected, const QItemSelection& deselected)
         { qDebug() << "selected =" << selected << endl << "deselected =" << deselected; }); 
      tableWidget->show(); 
      QTimer::singleShot(10000, [=](){ tableWidget->removeRow(0); });

      Within 10 seconds, select the first of two rows. You will see debug ouput. It will show you that row 0 was selected by your click. Then, after 10s, row 0 is removed automatically. Debug output now shows that row 1 is selected and row 0 is deselected.

      The latter doesn't make any sense to me. When removing row 0 I would expect the "new" row 0 being selected afterwards. Also the visually selected row still is row 0 and row 1 simply doesn't exist anymore.

      This also happens with a custom model and generic view and makes my application crash by pointing to a row that does not exist.

      Attachments

        Issue Links

          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
              silicomancer Bernhard Lindner
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes