我有一个功能想要连接所有Qpushbutton,但我不知道如何设置它。
现在我只使用 dict 列出所有attr,并过滤Qpushbutton,但我不知道如何设置,连接。
那是我的代码:
def test_fn(self):
item_dict = self.__dict__
for key in item_dict:
attr = item_dict[key]
if type(attr) is QPushButton:
print key
###that is i don't know how to set
# setattr(self,key,pyqtBoundSignal.connect(self.showx))
答案 0 :(得分:0)
我认为您应该可以直接使用connect:
def test_fn(self):
item_dict = self.__dict__
for key in item_dict:
attr = item_dict[key]
if isinstance(attr, QPushButton): # isinstance will also detect subclasses, but you might not need it
print key
attr.clicked.connect(self.showx)