[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: [PyQt] trigger on_item_changed when currentIndexChanged on combobox in qtablewidget
From: Dick_Kniep <dick.kniep () lindix ! nl>
Date: 2015-11-20 9:09:14
Message-ID: zarafa.564ee33a.41fb.4ac20b9910f70514 () mail ! int ! lindix ! nl
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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)
[Attachment #5 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" \
"http://www.w3.org/TR/html4/loose.dtd"><html> <head>
<meta name="Generator" content="Zarafa WebAccess v7.0.15-42709">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>trigger on_item_changed when currentIndexChanged on combobox in \
qtablewidget</title> <style type="text/css">
body
{
font-family: Arial, Verdana, Sans-Serif ! important;
font-size: 12px;
padding: 5px 5px 5px 5px;
margin: 0px;
border-style: none;
background-color: #ffffff;
}
p, ul, li
{
margin-top: 0px;
margin-bottom: 0px;
}
</style>
</head>
<body>
<p>Hi list,</p><p> </p><p>environment pyqt5, linu</p><p> </p><p>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:</p><p> </p><p>class \
timePointWidget(QTableWidget):</p><p> </p><p> def __init__(self, \
parent, protocol, operation):</p><p> \
super(timePointWidget, \
self).__init__(parent)</p><p>self.itemChanged.connect(self.on_item_changed)</p><p> </p><p> \
def on_item_changed(self, \
item):</p><p> print(item.row())</p><p> </p><p> def \
populate(self):</p><p> self.timepoints_underconstruction = \
[t for t in self.protocol.timepoints]</p><p> for row, tp \
in enumerate(self.timepoints_underconstruction):</p><p> \
value, unit = self.showtimepoint(tp)</p><p> \
self._populate_row(row, (tp.timepoint_description, tp.timepoint_repeat, \
value), unit )</p><p> </p><p> if not self.operation \
== 'Delete':</p><p> \
self.input_row(row+1)</p><p> \
self.resizeColumnsToContents()</p><p> </p><p> def input_row(self, \
row):</p><p> self._populate_row(row, (_('Add \
timepoint'), '', ''), _('min'))</p><p> \
self.setRowCount(row+1)</p><p> </p><p> def \
_populate_row(self, row, columns, combobox_value):</p><p> \
self.insertRow(row)</p><p> for col_idx, col in \
enumerate(columns):</p><p> item = \
QTableWidgetItem(str(col))</p><p> \
item.setText(str(col))</p><p> \
self.setItem(row, col_idx, item)</p><p> combo = \
QComboBox()</p><p> sig_mapper = \
QSignalMapper()</p><p> \
sig_mapper.mapped.connect(self.on_item_changed)</p><p> \
combo.currentTextChanged.connect(sig_mapper.map)</p><p> \
self.setCellWidget(row, 3, combo)</p><p> \
sig_mapper.setMapping(combo, combo)</p><p> \
[combo.addItem(unit) for unit, trans, factor in self.units]</p><p> \
combo.setCurrentText(combobox_value)</p><p> </p> </body>
</html>
[Attachment #6 (text/plain)]
_______________________________________________
PyQt mailing list PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic