I am trying to solve the sorting issue and found this answer: QTableWidget Integer
So I borrowed the code, and tried to test and fill multiple columns. However, the second column doesn't get filled for some reason. See below for the code I am using:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QTableWidget, QTableWidgetItem, QVBoxLayout
from PyQt5.QtCore import Qt
class Widget(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.widget_layout = QVBoxLayout()
self.table_widget = QTableWidget(101, 2)
self.table_widget.setSortingEnabled(True)
self.widget_layout.addWidget(self.table_widget)
self.setLayout(self.widget_layout)
for num in range(101):
item = QTableWidgetItem()
item.setData(Qt.EditRole, num)
self.table_widget.setItem(num, 0, item)
item2 = QTableWidgetItem()
item2.setData(Qt.EditRole, num)
self.table_widget.setItem(num, 1, item2)
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = Widget()
widget.show()
sys.exit(app.exec_())
Not sure what went wrong here. Thanks!