When inserting rows into QTableWidget, you need to disable sorting.
1. Disable Sorting
2. Insert Row(s), set all items in the row.
3. Enable Sorting
This is because, with sorting enabled, as soon as you insert a new item in a row, QTableWidget runs the sorting check on the new row item and relocates the item as per set sorting order, this means that the item row number is changed, and the row variable which you hold is no more valid, and when you to set the next item on the same row, it will give you spurious results, as the row variable is not valid any more
Other alternate to disable sorting, is to get the latest row number before setting the item, like this
1. Insert a new row (say row)
2. Set new item at row, at column 0
3. Get the new row number of the newly set item at column 0
4. Set next item at new row, at column 1
....next columns, as needed
Bookmarks