pyqt5 信号槽


pyqtSignal 的数据类型可以 int str,list
getimageSignal = pyqtSignal(QImage, list)

previewSignal = pyqtSignal([int,str],[str])

简单demo:

from PyQt5 import QtCore
from PyQt5.QtCore import Qt,pyqtSignal,QSize,QRect,QMetaObject, QCoreApplication, pyqtSlot,QPropertyAnimation,QThread

  1. from PyQt5 import QtWidgets,QtCore
  2. from untitled import Ui_Form
  3. import time
  4. class MyWindow(QtWidgets.QWidget,Ui_Form):
  5. _signal=QtCore.pyqtSignal(str) #定义信号,定义参数为str类型
  6. def __init__(self):
  7. super(MyWindow,self).__init__()
  8. self.setupUi(self)
  9. self.myButton.clicked.connect(self.myPrint)
  10. self._signal.connect(self.mySignal) #将信号连接到函数mySignal
  11. def myPrint(self):
  12. self.tb.setText( "")
  13. self.tb.append( "正在打印,请稍候")
  14. self._signal.emit( "你妹,打印结束了吗,快回答!")
  15. def mySignal(self,string):
  16. print(string)
  17. self.tb.append( "打印结束")
  18. if __name__== "__main__":
  19. import sys
  20. app=QtWidgets.QApplication(sys.argv)
  21. myshow=MyWindow()
  22. myshow.show()
  23. sys.exit(app.exec_())

  1. from PyQt5 import QtWidgets,QtCore
  2. from untitled import Ui_Form
  3. import time
  4. class MyWindow(QtWidgets.QWidget,Ui_Form):
  5. _signal=QtCore.pyqtSignal(str) #定义信号,定义参数为str类型
  6. def __init__(self):
  7. super(MyWindow,self).__init__()
  8. self.setupUi(self)
  9. self.myButton.clicked.connect(self.myPrint)
  10. self._signal.connect(self.mySignal) #将信号连接到函数mySignal
  11. def myPrint(self):
  12. self.tb.setText( "")
  13. self.tb.append( "正在打印,请稍候")
  14. self._signal.emit( "你妹,打印结束了吗,快回答!")
  15. def mySignal(self,string):
  16. print(string)
  17. self.tb.append( "打印结束")
  18. if __name__== "__main__":
  19. import sys
  20. app=QtWidgets.QApplication(sys.argv)
  21. myshow=MyWindow()
  22. myshow.show()
  23. sys.exit(app.exec_())

还有一对多,多对一的高级玩法,可以参考:

https://blog.csdn.net/broadview2006/article/details/80132757

你可能感兴趣的:(pyqt)