Using lambda expression to connect slots in pyqt
Beware! As soon as you connect your signal to a lambda slot with a reference to self, your widget will not be garbage-collected! That's because lambda creates a closure with yet another uncollectable reference to the widget.
Thus, self.someUIwidget.someSignal.connect(lambda p: self.someMethod(p))
is very evil :)
The QPushButton.clicked
signal emits an argument that indicates the state of the button. When you connect to your lambda slot, the optional argument you assign idx
to is being overwritten by the state of the button.
Instead, make your connection as
button.clicked.connect(lambda state, x=idx: self.button_pushed(x))
This way the button state is ignored and the correct value is passed to your method.