Is there a deselectRow for QTableView?
-
Hi. I have a table like this:


I want to sync the checkbox and selection, and am wondering whether a deselect row feature exists: the way I have implemented it so far is like this:
void TestConfig::checkBoxSelectionSync(){ //Detects whether the two are out of sync by checking whether the row activated is the same as the button clicked. for(int i = 0 ; i < ui->tableWidget_Configs->rowCount();i++){ QTableWidgetItem *button = ui->tableWidget_Configs->item(i, 0); bool buttonSelected = button->checkState(); if (buttonSelected != ui->tableWidget_Configs->item(i, 0)->isSelected()){ ui->tableWidget_Configs->selectRow(i); //Selects the line or deselects the line } } }I don't think selectRow is deselecting my rows and I haven't found anything in the documentation on this regard. Please let me know if more info is required.
-
Hi. I have a table like this:


I want to sync the checkbox and selection, and am wondering whether a deselect row feature exists: the way I have implemented it so far is like this:
void TestConfig::checkBoxSelectionSync(){ //Detects whether the two are out of sync by checking whether the row activated is the same as the button clicked. for(int i = 0 ; i < ui->tableWidget_Configs->rowCount();i++){ QTableWidgetItem *button = ui->tableWidget_Configs->item(i, 0); bool buttonSelected = button->checkState(); if (buttonSelected != ui->tableWidget_Configs->item(i, 0)->isSelected()){ ui->tableWidget_Configs->selectRow(i); //Selects the line or deselects the line } } }I don't think selectRow is deselecting my rows and I haven't found anything in the documentation on this regard. Please let me know if more info is required.
You have to access the QItemSelectionModel directly and use QItemSelectionModel::select() with the appropriate flags to deselect a row.