pyQt5基础学习-重载多种输入的槽函数 1.pyqtSignal([int, str], [str])(构造两种输出参数的信号)
当槽函数会有多种类型的函数输入时,需要进行重载,这里对信号构成进行重载,在绑定槽函数时,做指定操作
MultiSignal.py
""" 为类添加多个信号 """ from PyQt5.QtCore import * class MultiSignal(QObject): signal1 = pyqtSignal() signal2 = pyqtSignal(int) signal3 = pyqtSignal(int, str) signal4 = pyqtSignal(list) signal5 = pyqtSignal(dict) #声明一个重载版本,槽函数的参数可以时int和str类型, 也可以是int类型 signal6 = pyqtSignal([int, str], [str]) def __init__(self): super(MultiSignal, self).__init__() self.signal1.connect(self.signalCall1) self.signal2.connect(self.signalCall2) self.signal3.connect(self.signalCall3) self.signal4.connect(self.signalCall4) self.signal5.connect(self.signalCall5) #根据类型指定槽函数 self.signal6[int, str].connect(self.signalCall6) self.signal6[str].connect(self.signalCall6Overload) self.signal1.emit() self.signal2.emit(10) self.signal3.emit(1, "hello world") self.signal4.emit([1, 2, 3, 4, 5, 6]) self.signal5.emit({"name":"Bill", "age":30}) #指定发送的信号函数 self.signal6[int, str].emit(20, "test") self.signal6[str].emit("test") def signalCall1(self): print("signal1 emit") def signalCall2(self, val): print("signal2 emit, value:", val) def signalCall3(self, val, text): print("signal3 emit, value:", val, text) def signalCall4(self, val): print("signal4 emit, value:", val) def signalCall5(self, val): print("signal5 emit, value:", val) def signalCall6(self, val, text): print("signal5 emit, value:", val, text) def signalCall6Overload(self, val): print("signal5 emit, value:", val) if __name__ == "__main__": multisignal = MultiSignal()
每天更新pyQt5内容