Pyqt 如何将一个函数连接到所有 Qpushbutton

Pyqt how to connect a func to ALL Qpushbutton

我有一个功能想连接所有的Qpushbutton,但是我不知道怎么设置。

现在我只会用dict列出所有属性,过滤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))

我想你应该可以直接使用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)