import sys from PySide import QtGui def print_something(): print "print_something called" class Row(object): def __init__(self, table, row_idx): self.table = table self.row = row_idx def print_str(self): print "Row.print_str called" def add_to_table(self): sbox = QtGui.QSpinBox(self.table) sbox.valueChanged.connect(self.print_str) self.table.setCellWidget(self.row, 0, sbox) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) w = QtGui.QMainWindow() t = QtGui.QTableWidget(w) t.setFixedWidth(800) t.setFixedHeight(600) t.setColumnCount(1) t.setRowCount(10) t.setColumnCount(10) # these are saved in a list # and so seem to work rows = [] for x in range(0, 5): row = Row(t, x) row.add_to_table() rows.append(row) # these rows don't work # presumably due to a garbage # collection/reference counting bug for x in range(5, 10): row = Row(t, x) row.add_to_table() w.show() sys.exit(app.exec_())