Question

I have tableWidget with 7 columns (1. col - checkable items, 2. col - textEdit widgets, other columns populated with text using qTablewidgetItem).

After the table is populated, in order to be able to sort it when header of any column is clicked, I do this:

tableWidget.setSortingEnabled(1)
tableWidget.resizeRowsToContents()
tableWidget.horizontalHeader().sortIndicatorChanged.connect(tableWidget.resizeRowsToContents)

My question is: is that the best way to do it?, because when I have over 1000 rows it takes few seconds (up to 5) to sort table when header is clicked. If there is no third line, sorting is done instantly but size of rows get messed up, content cut off or too much white space around content... so, is there faster alternative for line 3?

Was it helpful?

Solution

Ok, I've finally find out why it takes that long to sort table: every time after table is populated I connect sortIndicatorChanged signal but never disconnect it. Solution is to simply disconnect it before populating table and connect it again when populating is finished.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top