I want to input data in my table and then have it appear in my combo box after pressing 'ok' pushbutton in pyqt. May I know how to go about doing that? Whenever I run my code it just says there is an error at self.comboBox.addItem(item). I don't know which other command to use. Here is part of my code:
def setup(self, Dialog):
...
...
self.comboBox = QtGui.QComboBox(Dialog)
self.comboBox.setGeometry(QtCore.QRect(20, 100, 431, 22))
self.comboBox.setObjectName(_fromUtf8("comboBox"))
self.tableWidget = QtGui.QTableWidget(Dialog)
self.tableWidget.setGeometry(QtCore.QRect(20, 470, 651, 71))
self.tableWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
self.tableWidget.setTextElideMode(QtCore.Qt.ElideRight)
self.tableWidget.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerItem)
self.tableWidget.setRowCount(1)
self.tableWidget.setColumnCount(129)
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.horizontalHeader().setVisible(True)
self.tableWidget.horizontalHeader().setDefaultSectionSize(25)
self.tableWidget.horizontalHeader().setMinimumSectionSize(26)
self.tableWidget.verticalHeader().setDefaultSectionSize(25)
self.tableWidget.verticalHeader().setHighlightSections(True)
self.pushButton_7 = QtGui.QPushButton(Dialog)
self.pushButton_7.setGeometry(QtCore.QRect(220, 650, 75, 23))
self.pushButton_7.setObjectName(_fromUtf8("pushButton_7"))
self.pushButton_7.clicked.connect(self.additem)
def retranslateUi(self, Dialog):
...
...
self.tableWidget.setSortingEnabled(False)
def additem(self):
item = self.tableWidget.item(0,0)
self.comboBox.addItem(item)
UPDATE: The solution only works for the first box of my tablewidget. I tried to do it like this:
def additem(self):
while true:
item = self.tableWidget.item(0, 0).text()
self.comboBox.addItem(item)
item1 = self.tableWidget.item(0, 1).text()
self.comboBox.addItem(item1)
However, I just keep getting the error that 'NoneType' object has no attribute 'text'
UPDATE: I tried your suggestion. I tried to upload images so it would be clearer but I need 10 reputation in order to do so. Anyway, I typed this in the tablewidget: 11 22 33 44 each one in one box for four boxes. But only 11 appeared in combobox after pressing 'ok'. It doesn't work even if I typed my value on the other boxes, it only works for the first box. What I need is for them to appear as '11, 22, 33, 44' in my combo box. Would it be possible to do this? As well as for all 128 columns of my tablewidget?