PDA

View Full Version : problem removing selected rows from QTableWidget



milli
5th May 2011, 00:23
I want to remove selected rows from QTableWidget..When i click on the button,if i have,for example three selected items only 2 are deleted.
Why this occurs?
This is my code:

QList <QTableWidgetItem *> items = ui->tableWidget->selectedItems();

for (int x=0;x<ui->tableWidget->rowCount();x++)
{
if(items.at(x)->isSelected())
ui->tableWidget->removeRow(x);
}

ChrisW67
5th May 2011, 09:37
The first time you remove a row subsequent row numbers change. For example, remove row 2 and row 3 becomes the new row 2, you then increment x and look at row 3. The original row 3 never gets looked at.