[PyQt] trigger on_item_changed when currentIndexChanged on combobox in qtablewidget

Dick Kniep dick.kniep at lindix.nl
Fri Nov 20 09:09:14 GMT 2015


Hi list,

 
environment pyqt5, linu

 
We designed a editable qtablewidget with a combobox in one of the cell. Everything works as planned, except for the combobox. When an item is selected in the combobox, this should trigger a function so that the changes can be stored. For the other columns this works OK, however the "on_item_changed" is method is NOT triggered when one changes the combobox. My code is as follows:

 
class timePointWidget(QTableWidget):

 
    def __init__(self, parent, protocol, operation):

        super(timePointWidget, self).__init__(parent)

self.itemChanged.connect(self.on_item_changed)

 
    def on_item_changed(self, item):

 print(item.row())

 
    def populate(self):

        self.timepoints_underconstruction = [t for t in self.protocol.timepoints]

        for row, tp in enumerate(self.timepoints_underconstruction):

            value, unit = self.showtimepoint(tp)

            self._populate_row(row, (tp.timepoint_description, tp.timepoint_repeat, value), unit )

 
        if not self.operation == 'Delete':

            self.input_row(row+1)

        self.resizeColumnsToContents()

 
    def input_row(self, row):

        self._populate_row(row, (_('Add timepoint'), '', ''), _('min'))

        self.setRowCount(row+1)

 
    def _populate_row(self, row, columns, combobox_value):

        self.insertRow(row)

        for col_idx, col in enumerate(columns):

            item = QTableWidgetItem(str(col))

            item.setText(str(col))

            self.setItem(row, col_idx, item)

        combo = QComboBox()

        sig_mapper = QSignalMapper()

        sig_mapper.mapped.connect(self.on_item_changed)

        combo.currentTextChanged.connect(sig_mapper.map)

        self.setCellWidget(row, 3, combo)

        sig_mapper.setMapping(combo, combo)

        [combo.addItem(unit) for unit, trans, factor in self.units]

        combo.setCurrentText(combobox_value)

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20151120/6b65ba0c/attachment.html>


More information about the PyQt mailing list