PDA

View Full Version : Removing items from QtableWidget



algajard
16th March 2009, 18:50
Hey kids,

I'm using Qt-4.5 with Qt-Creator running under linux and I have the following problem. I have a QTableWidget with "n" rows. Then I select "m" rows for deletion. My problem is that the method only deletes "m-1" rows from the table.

QList<QTableWidgetSelectionRange> range=tipos_table->selectedRanges();

for(i=0;i<range.size();i++)
{
top=range.at(i).topRow();
bottom=range.at(i).bottomRow();
for(j=top;j<=bottom;j++)
tipos_table->removeRow(j);
}

That is the method I wrote. The method visits all the items but the last item will not be deleted.

Clues, ideas ?

Regards and thanks,

pckoster
17th March 2009, 09:31
30-years old kid responding :p

Have you tried to remove the rows in reverse order? I can imagine when you start removing the rows from the top, the rows further down on are shifted upwards, thus not matching the initial rowcount you queried using selectedRanges().

I suggest reversing both the list iteration (variable i) as well as the row removal code (variable j)