[Qt-interest] removing items from QtableWidget

Malyushytsky, Alex alex at wai.com
Mon Mar 16 21:02:14 CET 2009


Nobody called me "a kid" for 20+ years.
Thanks ?

Look at your loop

         for(j=top;j<=bottom;j++)
                tipos_table->removeRow(j);

It has interesting effects. If you haave rows below the range you want to be deleted, it will leave some rows you were trying to delete and delet some you did not want to.

Assume you have two rows, j=0

1 row1
2 row2

You remove row1, what happens if follow your code?

1 row2 // index of row2 and below changed
2 ......  ->


Now j=1

1 row2
2 ...

You are going to delete second line, which is not want you wanted to do.


To fix it, you either reverse loop, so you delete last row first:
         for(j=bottom; j>= top;j--)
                tipos_table->removeRow(j);

or delete first row  all the time
         for(j=top;j<=bottom;j++)
                tipos_table->removeRow(top);

Best regards,
           Alex


-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of algajard
Sent: Monday, March 16, 2009 8:56 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] removing items from QtableWidget

Hey kids,

I'm new in the list. 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,

--
"Talk is cheap. Show me the Code"
"'Regression testing'? What's that? If it compiles, it is good, if it
boots up it is perfect."
-----------------------
Alvaro Esteban Gajardo Becerra
Estudiante Informática - Universidad del Bío Bío
Linux User #407663 counter.li.org
Chillán
Chile
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."




More information about the Qt-interest-old mailing list