代码:
myresult = [(449, u'text1', u'checkbox'), (454, u'text2', u'textbox'), (455, u'text3', u'textbox')]
row = 0
for x, x1, x2 in myresult:
g = int(''.join(map(str, x))) # int type
l = ''.join(x1) # string type
k = ''.join(x2) # string type
rcount_general = self.tableWidget.rowCount()
self.tableWidget.insertRow(rcount_general)
r = 0
for i in range(rcount_general + 1):
if (k == "textbox"):
self.cb = QtGui.QComboBox()
lis = ("---select---", "description", "multiple_input")
self.cb.addItems(lis)
self.cb.setCurrentIndex(1)
self.tableWidget_2.setCellWidget(rcount_general, 2, self.cb)
elif (k == "checkbox"):
self.cb = QtGui.QComboBox()
lis = ("---select---", "description", "multiple_input")
self.cb.addItems(lis)
self.cb.setCurrentIndex(2)
self.tableWidget_2.setCellWidget(rcount_general, 2, self.cb)
self.tableWidget.setItem(row, 0, QtGui.QTableWidgetItem(g))
self.tableWidget.setItem(row, 1, QtGui.QTableWidgetItem(l))
r = r + 1
row = row + 1
错误:
g =''.join(map(str,x)) TypeError:map()的参数2必须支持迭代
请检查所附图像的预期输出,谢谢。
答案 0 :(得分:1)
我不明白为什么要使用连接,这里只需要使用枚举:
myresult = [(449, u'text1', u'checkbox'), (454, u'text2', u'textbox'), (455, u'text3', u'textbox')]
for row, result in enumerate(myresult):
self.tableWidget.insertRow(self.tableWidget.rowCount())
for column, value in enumerate(result):
item = QtWidgets.QTableWidgetItem(str(value))
if column == 2:
combo = QtWidgets.QComboBox()
combo.addItems([value, "---select---", "description", "multiple_input"])
self.tableWidget.setCellWidget(row, column, combo)
self.tableWidget.setItem(row, column, item)