PDA

View Full Version : A problem with sorting QTableWidget by column



tehman
6th February 2012, 08:37
Hello!

My QTableWidget object is being filled from a database. Everything went okay until I had to sort the second column by ascending. So I wrote:
ui.tableWidget->sortByColumn(2, Qt::AscendingOrder);
When I ran the application I found that a lot of cells of the table widget are empty. Why is that so? Would anybody help me please?

Added after 15 minutes:

Oh, I think I have just solved the problem. I have added ui.tableWidget->setSortingEnabled(false); before filling the widget ui.tableWidget->setItem(rowNumber, i ,item); and after that - ui.tableWidget->setSortingEnabled(true);
Now everything works fine.
Sorry for that thread. I asked a question and answered it on my own.

jgver
15th February 2012, 15:56
Thanks for this post. I just ran into the same problem, and this post saved me!