PDA

View Full Version : QTableWidget sorting



migel
5th June 2011, 18:31
QTableWidget


this->setColumnCount(4);
this->setSortingEnabled(true);

then display my rows... works fine.
Now when I add


this->sortItems( 1, Qt::AscendingOrder );

I have garbage in rows, basically no data in 2 and 4 columns.

Same when I remove to sortItems()... and click on header to sort the column

have U seen that before ?

I use setItem() to insert it.

Please help

Santosh Reddy
6th June 2011, 00:08
You need to disable sorting while you are setting / inserting the items.

...
this->setSortingEnabled(false);
this->setItem(...);
this->setSortingEnabled(true);
...
This is because as soon as you set/insert an item, table will automatically sort again and the just inserted item will be moved to some new row, but you will still try use the old row number, and things get messed up and your program may even crash.