在 pyqt4 中的 QTableWidget 中存储列表值 python

Store list values in QTableWidget in pyqt4 python

代码:

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)) 类型错误:map() 的参数 2 必须支持迭代

请检查下面的附件图像是否有预期的输出。提前谢谢你

不明白为什么要用join,这里只需要用enumerate:

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)