Question

I have a QTableView with check boxes was created by:

 QStandardItem* checkBox = new QStandardItem(true);
 checkBox->setCheckable(true);
 checkBox->setCheckState(Qt::Unchecked);
 model->setItem(row, 0, checkBox);
ui->tableView->setModel(model);

Now I want to get all the chceked rows. As I found in many samples code I have to write something like this:

 QItemSelectionModel *select = ui->tableView->selectionModel();
 QModelIndexList selectedSensosrs = select->selectedRows();
 for(int i = 0; i < selectedSensosrs.count(); i++)
 {
            //do something
  }

But this code doesn't work, the count value is zero even I checked a few items!! I looked a lot for a better way to dothat, but didn't find...:(

Can anyone please help me?

Was it helpful?

Solution

Slight misconception on your side. Selected rows is not a row, which contains a selected checkbox, but a row, which is highlighted. I am afraid you must iterate through all your cells and query the QCheckState.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top