首先设置一下表格信息:
self.data=(('001', '简自豪', '2018-11', 4, 3, 2, 1), ('002', 'MLXG', '2018-11', 5, 4, 3, 2), ('003', 'Letme', '2018-11', 6, 5, 4, 3), ('004', 'Ming', '2018-11', 4, 3, 2, 1), ('005', 'Xiaohu', '2018-11', 5, 4, 1, 2))
使用for特性时,会出现某些单元格被隐藏的奇葩现象
for each1 in self.data: # 设置表内容
for each2 in each1:
if each2 != None:
save=str(each2)
newItem = QTableWidgetItem(save)
self.tableWidget.setItem(self.data.index(each1), each1.index(each2),newItem)
若使用for i形式,单元格则不会被隐藏:
for i in range(len(self.data)):
for j in range(len(self.data[i])):
if self.data[i][j] != None:
save=str(self.data[i][j])
newItem = QTableWidgetItem(save)
self.tableWidget.setItem(i,j,newItem)
