Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如果调用类方法,是否向所有实例发出信号?_Python_Qt_Python 3.x_Pyside - Fatal编程技术网

Python:如果调用类方法,是否向所有实例发出信号?

Python:如果调用类方法,是否向所有实例发出信号?,python,qt,python-3.x,pyside,Python,Qt,Python 3.x,Pyside,我在许多不同的页面和表单上有许多相同类型的按钮(源自QPushButton)。我需要一个全局开关来更改实例的属性,例如启用/禁用所有。是否可以为此目标调用类方法。一个想法是在静态数组中保存每个新引用(\uuuuu new\uuuuu/\uuuuu init\uuuuuu?),但是否有pythonic和垃圾收集器兼容的方法?从根目录(主窗口)到最后一个角点的标准递归搜索将非常糟糕 使用:Python 3.3+pyside+Qt4.8是的,可以: class MyButton(QPushButton

我在许多不同的页面和表单上有许多相同类型的按钮(源自
QPushButton
)。我需要一个全局开关来更改实例的属性,例如启用/禁用所有。是否可以为此目标调用类方法。一个想法是在静态数组中保存每个新引用(
\uuuuu new\uuuuu
/
\uuuuu init\uuuuuu
?),但是否有pythonic和垃圾收集器兼容的方法?从根目录(主窗口)到最后一个角点的标准递归搜索将非常糟糕

使用:Python 3.3+pyside+Qt4.8是的,可以:

class MyButton(QPushButton):

    BigSwitch = SomeQObjectThatDefinesTheSignal()

    def __init__(self, ...):
        ...
        BigSwitch.the_signal.connect(self.some_slot)

    def some_slot(self, ...):
        #handle the change of the property

    @classmethod
    def enable(cls):
        cls.BigSwitch.the_signal.emit(...)
您还可以使用
staticmethod
MyButton.BigSwitch
代替class方法