我想获取qtablewidget列(总计)中存在的所有项目的总和,当用户单击列标题(总计)时,总和将b打印在下一列(sum)中,如您在图像中看到的
[![{https://i.stack.imgur.com/ynN9g.png][2]][2]
def data(self):
con = mdb.connect(host='localhost', )
cur = con.cursor()
cur.execute("USE table_1")
cur.execute(""SELECT table_no, gametype, total from tables "")
self.tableWidget.setRowCount(0)
self.tableWidget.setColumnWidth(1, 130)
self.tableWidget.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem('Table No'))
self.tableWidget.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem('Game Type'))
self.tableWidget.setHorizontalHeaderItem(2, QtWidgets.QTableWidgetItem('Total'))
self.tableWidget.setHorizontalHeaderItem(3, QtWidgets.QTableWidgetItem('Sum'))
for row_number, row_data in enumerate(cur):
self.tableWidget.insertRow(row_number)
for column_number, data in enumerate(row_data):
self.tableWidget.setItem(row_number, column_number, QtWidgets.QTableWidgetItem(str(data)))
con.commit()
这是我用来从数据库获取数据的代码