[PySide] sender connect to multi slot

Carlos Zuniga carlos.zun at gmail.com
Fri Jun 6 02:14:20 CEST 2014


On Thu, Jun 5, 2014 at 11:38 AM, OisLone <oislone at ois.idv.tw> wrote:
> Hello ALL:
>
> Now I can  use  methods  like
>
> def FuncA ():
>       print ("AAA")
>
> def FuncB ():
>       print ("BBB")
>
> q = QPushButton ("TEST")
> q.clicked.connect (FuncA)
> q.clicked.connect (FuncB)
>
> I  can use another  way?  Like  Python List
> For example:
>
> def FuncA ():
>       print ("AAA")
>
> def FuncB ():
>       print ("BBB")
>
> q = QPushButton ("TEST")
> lis = [FuncA, FuncB]
> q.clicked.connect (lis)
>
> Because only  need to define a  variable  lis,  I  can set up multiple  QPushButton's  connect,  if  the  need to change,    can modify the  lis  only.
>

You could create a closure that calls all those functions:

def multifunc(*args):
    def _multifunc():
        for fn in args:
            fn()
    return _multifunc

And use it like this:

funcs = multifunc(FuncA, FuncB)
q.clicked.connect (funcs)


Code is untested but it should get you going.



More information about the PySide mailing list