从Qtablewidget PyQt5获取列值以列出

时间:2019-12-30 23:00:56

标签: python pyqt5 qtablewidget

我正在编写一些包含qtablewidget的代码,需要从列数据中获取列表,这是一个简单的代码。

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot
list1= ['Lx', 'Mx', 'Nx', 'Ox']
list2 = []

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.title = 'table'
        self.initUI()
    def initUI(self):
        self.setWindowTitle(self.title)
        self.setGeometry(200,200, 300, 300)
        self.createTable()
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.tableWidget)
        self.setLayout(self.layout)
        self.show()

    def createTable(self):
        self.tableWidget = QTableWidget(4, 2)
        self.tableWidget.setHorizontalHeaderLabels(['listA', 'listB'])
        for row, i  in enumerate(list1):
                item1= QTableWidgetItem(i)
                item2= QTableWidgetItem(i+'sfs')
                self.tableWidget.setItem(row, 0, item1)
                self.tableWidget.setItem(row,1, item2)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())  

我需要将column(1)(list2)数据检索到列表中
尝试过

list2.append (item2)
comes with 
['Lxsfs']
['Mxsfs']
['Nxsfs']
['Oxsfs']

我正在寻找['Lxsfs','Mxsfs','Nxsfs','Oxsfs']

是否可以从“ qtablewidget”获取此列表

谢谢

0 个答案:

没有答案