我在许多不同的页面和表单上有许多相同类型的按钮(从QPushButton
派生)。我想要一个全局开关来更改实例的属性,例如启用/禁用全部。是否可以调用此目标的类方法。一个想法是保存每个新的引用(__new__
/__init__
?)在静态数组中,但是有pythonic和垃圾收集器兼容的方式吗?从根(主窗口)到最后一个角落的标准递归搜索将是可怕的。
使用: Python 3.3 + pyside + Qt4.8
发布于 2013-05-30 09:51:43
是的,这是可能的:
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
来代替类方法。
https://stackoverflow.com/questions/16832750
复制相似问题