I need first column of my QTableWidget to be populated as: Row: 1, Row: 2...Row: 100 , but sorting doesn't work as expected (numerically). Sorting works fine with this code, but I don't get expected text:
for i in range(0, self.rows):
item = QtGui.QTableWidgetItem()
item.setData(Qt.DisplayRole, "Row: %s" %(i) )
item.setData(Qt.EditRole, i)
self.ui.tableWidget.setItem(i, 0, item)
I get: 1,2,3,4... instead of Row: 1, Row: 2, Row: 3... I expected that EditRole will be used for editing purposes (for numerical sorting, which works fine) but I also expected that text will be shown because it was set with DisplayRole. Can I do this that way somehow or writing function for purposes of sorting is the only way?