[PyQt] How do you explicitly connect parameterless signals?

Russell Warren russ at perspexis.com
Sat May 24 00:08:43 BST 2014

I have some cases where I want to decorate my slots, where the decorator
has a typical (*args, **kwargs) catch-all signature.  Unfortunately, when
doing this, I'm unable to connect the signals and slots properly to a
parameter-free overload when one with parameters is available.

>From the docs I thought it could be explicitly done at the connection side
with the use of:


or it could be explicit at the slot instead (?) that we want the
parameter-free one via:

    def foo():

but I can't get either of these to work.  When my button slot has *args in
the params, I always get the 'checked' boolean.

How do I force PyQt5 to *not* connect up the version with the (bool, )

Full example code is below, with a stripped down example of the decorator

import sys
from PyQt5 import QtWidgets
from PyQt5.QtCore import pyqtSlot

app = QtWidgets.QApplication(sys.argv)

w = QtWidgets.QWidget()
w.setWindowTitle('Signal connection checking')

b1 = QtWidgets.QPushButton("Connection to ()")
b2 = QtWidgets.QPushButton("Connection to (checked)")
b3 = QtWidgets.QPushButton("Connection to (*args)")

layout = QtWidgets.QVBoxLayout(w)

def bogus_decorator(f):
    def wrapper(*args):
        print "wrapper called with args = %r" % (args, )
        return f() #<-- have to do this to make the code work
        #should be the code below, but it fails since we call with
        #an unexpected arg and get a corresponding TypeError.
        #return f(*args) #<--- will fails since it passes an unexpected arg
    return wrapper

def onVoidClick():
    print "normal (void) clicked!"

def onBoolClick(checked):
    print "normal (bool) clicked!"

@pyqtSlot() #<-- shouldn't this force the parameter-free overload?
#@pyqtSlot()  #<--- order does not matter
def onWrappedStarClick():
    #this always gets called with the (bool) overload
    print "Actual handler fired!"


#How to connect this next one so that it works like onVoidClick()?
# - explicitly defining the slot with @pyqtSlot() does not work
# - explicitly connecting an overload with clicked[()].connect doesn't work


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140523/586ddf9e/attachment.html>

More information about the PyQt mailing list