I am trying to connect a signal (currentIndexChanged) from a combobox I have put in a tablewidget. However, I do not seem to get the correct information of which comboxbox in the tablewidget that has changed.
This is my current implementation (reduced for simplicity):
def SetupTable(self):
for k in range (0,2):
self.tableWidget.insertRow(k)
comboBox = QtWidgets.QComboBox()
self.tableWidget.setCellWidget(k,1,comboBox)
def UpdateTable(self):
for i in range (0,self.tableWidget.rowCount()):
comboBox = QtWidgets.QComboBox()
for item in Tcmp.GetObject():
comboBox.addItem(item.GetName())
print('Combobox Row:{}'.format(i))
comboBox.currentIndexChanged.connect(lambda : self.handleTableCombo(i))
self.tableWidget.setCellWidget(i,1,comboBox)
def handleTableCombo(self,row):
print('Hello')
print(row)
I first SetupTable() because The Tcmp.GetObject is not ready at this point in time. I then later call UpdateTable() to get the table updated to the Object.
The problem is that the handleTableCombo() does not give me any information regarding which combobox is changed (by the user)
This is the print output from UpdateTable:
Combobox Row:0
Combobox Row:1
Print output from handleTableCombo, regardless of which combobox is changed and which item is selected:
Hello
1
In addition, I would appreciate if anyone has some tips on how I would avoid creating a new combobox everytime updateTable is called. I tried:
#comboBox = self.tableWidget.cellWidget(i, 1)
But .cellWidget does not seem to understand that it is a combobox.
This is PyQt5.
Thank you in advance.