I have a QTableWidget that I populate as follows:
// Clear the table this->topPatchesTableWidget->setRowCount(0); this->topPatchesTableWidget->setRowCount(numberToDisplay); for(unsigned int pairId = 0; pairId < numberToDisplay; ++pairId) { // Display patch match scores QTableWidgetItem* myLabel = new QTableWidgetItem; myLabel->setData(Qt::DisplayRole, myValues[pairId]); this->tableWidget->setItem(pairId, 0, myLabel); ... fill other columns ... }
(I have some other user interface elements for setting properties that compute values ββin myValues). If I change the properties, re-read and re-create the table, everything will work as expected. If I sort a table by clicking on one of the headers, it is sorted correctly. HOWEVER, if at the moment (after sorting) I press the button again to recalculate the values ββand recreate the table, the table is very broken. That is, many of the cells are empty, and cells that are not empty do not look in a specific order.
Adding a manual call
this->tableWidget->sortByColumn(0, Qt::AscendingOrder);
at the beginning of my CreateTable function, everything works as expected, but, of course, the newly created table is sorted by column 0, not the column that was selected for the last sort.
Does anyone have any idea why everything would be so wrong without calling sortByColumn? (I tried to make a simple example, but I cannot reproduce the problem in a demo program).
Thanks,
David
source share