View Full Version : PyQt5 callback of different name being invoked on valueChanged

30th August 2018, 02:09
Hello, everyone! I'm having some trouble with callback in my PyQt5 app.

I want more than one callback available to an object, but defining any subsequent callback in an object overwrites all previous callbacks. However, the callbacks are decorated, which seems to be messing with things. How should I define object-level callbacks, so I can use self in them?

In the following example, which you can run on any computer with Python 3.x and PyQt5.11.x, a spinbox is hooked up to two valueChanged callbacks. These are called A and C. However, the second callback C never triggers, and a third callback D triggers instead. D should not trigger.

from PyQt5 import QtWidgets
from PyQt5.QtCore import pyqtSlot

def silenceCallbacks(*elements):
"""Silence events for the duration of a callback. Mostly skipped for this reproduction."""
def silenceCallbacksOf(callback):
def silencedCallback(self, *args, **kwargs):
callback(self, *args, **kwargs)
return silencedCallback
return silenceCallbacksOf

def callbackA(px: int):
#correctly called
print('got A', px)

@pyqtSlot(int) #this overwrites the last three functions
def callbackB(px: int):
#correctly not called
print('got B', px)

class RecordingSettings(QtWidgets.QDialog):
def callbackC(self, px: int):
#incorrectly not called
print('got C', px)

@pyqtSlot(int) #this overwrites the previous pyqtSlot-decorated function
def callbackD(self, px: int):
#incorrectly called
print('got D', px)

def __init__(self, window):

spin = QtWidgets.QSpinBox()


layout = QtWidgets.QVBoxLayout()

app = QtWidgets.QApplication([])
recSettingsWindow = RecordingSettings(app)

If anyone's got any ideas, that'd be much appreciated. Thank you. :crying: