简体   繁体   中英

PySide Signal with Argument

QGroupBox has the signal clicked which has an optional checked parameter. Suppose I'm trying to connect a slot to it inside of some class like so: box.clicked.connect(self.func) , so the declaration of the slot must be def func(self, checked) , but func is being called with only one argument. How do I get the desired behaviour of func being called with both self and the optional checked arguments?

The behaviour of signals with optional default parameters differs between PyQt and PySide. In PyQt, the default parameter is always sent, but in PySide you have to explicitly request it:

    box.clicked[bool].connect(self.func)

This is a much better design choice, I would say, as the PyQt behaviour can often lead to bugs if you forget that a default value will be sent even though you didn't ask for it. A case of explicit being better than implicit...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM