PyQt5 发送信号

如果不需要传递参数,self._singal.emit() 中,和回调函数都不加参数即可
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QMainWindow

class Sub_packages_window(QMainWindow, Ui_MainWindow):

    _singal = pyqtSignal(str)

    def __init__(self, parent=None):
        super(Sub_packages_window, self).__init__(parent)
        self.setupUi(self)
		self._singal.connect(self.show_success_dialog)  # 连接回调

	def do_something(self):
		self._singal.emit('成功...')  # 发送信号,emit 的信息发送到回调里面的参数那里

    def show_success_dialog(self, showmsg):

        self.logger.debug('show dialog msg')
        box = QMessageBox()
        font = QtGui.QFont()
        font.setFamily("微软雅黑")
        font.setPointSize(12)
        font.setBold(True)
        font.setWeight(75)
        box.setFont(font)
        box.setWindowTitle('提示')
        box.setText(showmsg)

        if showmsg.startswith('成功'):
            box.setStyleSheet('color:green')
            btn_yes = box.addButton('确定', QMessageBox.YesRole)
            box.setIcon(1)
            box.exec_()
            if box.clickedButton() == btn_yes:
                self.logger.debug('OK !!!\n\n\n\n')
                QFileDialog.getOpenFileNames(None, '查看apk文件', output_path, 'APK Files (*.apk)')
        else:
            box.setStyleSheet('color:red')
            box.addButton('确定', QMessageBox.YesRole)
            box.setIcon(3)
            box.exec_()

你可能感兴趣的:(PyQt5 发送信号)