pyqt signal 发射参数的类型

'''
conclusion:
QtCore.pyqtSignal is able to send several types of variable
including int QString QStringList list dict
'''

from PyQt4 import QtGui, QtCore
import sys

class prowler(QtGui.QWidget):
    switchSig = QtCore.pyqtSignal(dict)
    def __init__(self, parent=None):
        super(prowler, self).__init__(parent)
        btnLayout = QtGui.QHBoxLayout()
        mainLayout = QtGui.QVBoxLayout()
        
        okBtn = QtGui.QPushButton("OK")
        applyBtn = QtGui.QPushButton("b")
        quitBtn = QtGui.QPushButton("c")
        
        btnLayout.addStretch()
        btnLayout.addWidget(okBtn)
        btnLayout.addWidget(applyBtn)
        btnLayout.addWidget(quitBtn) 
        mainLayout.addLayout(btnLayout)
        self.setLayout(mainLayout)

        okBtn.clicked.connect(self.callforhelp)

    def callforhelp(self):
        self.switchSig.emit({"mon":1, "tue":2, "wen":3})

class main(QtGui.QWidget):
    def __init__(self, parent=None):
        super(main, self).__init__(parent)
        widget = prowler(self)
        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(widget)
        self.setLayout(mainLayout)

        widget.switchSig.connect(self.reaction)

    def reaction(self, string):
        print string
if __name__ == '__main__': 
    app = QtGui.QApplication(sys.argv)
    Jenney = main()
    Jenney.show()
    sys.exit(app.exec_())



一直对于pyqt中的signal可以emit的参数类型有些犹豫

今天试了一下,发现基本没有类型上的限制,还是挺好用的

你可能感兴趣的:(list,String,Class,import,Signal,Types)