I am trying to insert and display integers in my QTableWidget. They don't display. It works if I convert everything to strings, but then I can't sort columns numerically--only lexically (1, 10, 100, etc.). This is using PyQt.
I've tried some of the suggested solutions, using QTableWidgetItem.setData(someRole,intValue), bu then nothing at all displays. I've tried, Qt.UserRole, DisplayRole and Edit Role. (I don't understand why these Roles are needed to display integers, but have just followed the examples). My specific code is:
item = QTableWidgetItem()
item.setData = (Qt.DisplayRole,intValue)
myTable.setItem(row, column, item)
The following code works, but for strings only:
item = QTableWidgetItem(str(intValue))
myTable.setItem(row, column, item)
Also, the suggestions for reading the data back, only show the object location, not the actual data. Example, using Eric as an interpreter shell:
item.data(Qt.DisplayRole)
Response: PyQt4.QtCore.QVariant object at 0x1f01fa60
or this:
item.data(Qt.EditRole).data()
Response: sip.voidptr object at 0x1e904a80
Any insight is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…