c++qtqtableview

Deselect a single row in QTableView


I am implementing an invert selection function where I get the selected items, select everything, and then I want to iterate over the list of selected items to deselect them.

QModelIndexList indexs = this->selectedIndexes();
this->selectAll();
foreach(QModelIndex index, indexs)
{
   // Deselect row at index....
}

Solution

  • You can access the selectionModel and call select(index, QItemSelectionModel::Deselect) on it. You can also loop over all indices and call toggle.