pythonenumspyqtsignals-slotsqtcpsocket

Q_ENUMS in PyQt4


I would like to use facilities of enumeration of Qt. I saw in documentation of the module of QtCore there is a macros of Q_ENUMS, but I do not know and information how to use him.


Solution

  • In python (and PyQt), the way to create an enum is like this:

    class MyEnum(object):
        One = 1
        Two = 2
        Three = 3
    

    If you need more functionality than that, please give more details of what you are trying to do.

    EDIT

    Looking at the documentation for QAbstractSocket.stateChanged I can see it refers to "Creating Custom Qt Types". I am not aware of any need for registering metatypes in PyQt4, so all you need to do to use this signal is connect it to an appropriate handler:

    class Socket(QTcpSocket):
        def __init__(self):
            QTcpSocket.__init__(self)
            self.stateChanged.connect(self.handleStateChanged)
    
        def handleStateChanged(self, state):
            print state