Search code examples
pythonqtqt4pyqtpyqt4

How to Get Many QComboBoxes' Text from QTableWidget


i have inserted lots of QComboBox into a QTableWidget with setCellWidget (I don't know the number of qcomboboxes because it's coming from MySQL). But when I want to get its text from table with

self.table.item(0,1).itemText() 

or

self.table.item(0,1).text() 

or

self.table.item(0,1).currentText() 

it doesn't work. Normally I can get text with combobox.currentText() but table has many comboboxes and I don't know the row and column (x, y) info. So I should use something like .item(14,1).text()


Solution

  • If you've used setCellWidget, then calling cellWidget(0,1) instead of item(0,1) will return you a QWidget instead of a QTableWidgetItem.

    You may need to cast this QWidget to a QComboBox, but then you should be able to call currentText().