I have created a QTableWidget in which for a column I am setting a combobox QComboBox using setCellWidget function. It works fine .
This is how i set up the qtablewidget
cb = QComboBox()
cb.addItems(["Java", "C#", "Python"])
qtablewidget.setCellWidget(row_number, column_number , cb )
but now when I iterate through the QTableWidget , I cannot figure out how to get the selected value of the combobox for each row ?
You have to use the cellWidget()
method to get the widget given the column and the row, and then use the currentText()
method.
for r in range(qtablewidget.rowCount()):
for c in range(qtablewidget.columnCount()):
widget = qtablewidget.cellWidget(r, c)
if isinstance(widget, QComboBox):
current_value = widget.currentText()
print(current_value)