QTableWidget: avoid complete redrawing when an item is removed

When an item gets removed from QTableWidget, the dataChanged() signal
is sent out with an invalid index. This triggers a complete repaint
which is not needed since only one cell is changed.
Fix it by retrieving the model index *before* the internal structure is
cleaned for the given item since otherwise index() will no longer find
the item and return an invalid index.

Change-Id: Ia0d82edb6b44118e8a1546904250ca29d9c45140
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
Christian Ehrlicher 2020-01-31 20:51:03 +01:00
parent 3c20b9b973
commit 1559c328d5

View File

@ -247,8 +247,8 @@ void QTableModel::removeItem(QTableWidgetItem *item)
{
int i = tableItems.indexOf(item);
if (i != -1) {
tableItems[i] = 0;
QModelIndex idx = index(item);
tableItems[i] = nullptr;
emit dataChanged(idx, idx);
return;
}