Pyqt如何将func连接到ALL Qpushbutton

时间:2017-07-31 10:13:01

标签: python pyqt pyqt4

我有一个功能想要连接所有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))

1 个答案:

答案 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)