简体   繁体   中英

how to get the selected combobox value from QTableWidget?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM