How to declare enums in Python and expose to QML?



  • In C++ one can simply declare an enum as following:

    enum class MyEnum{One, Two, Three}
    

    Then using the Q_ENUM macro and registering the object using qRegisterType one is able to use the enums in QML. How can I do this in PySide2. I am aware that Python possesses enum capabilities (from enum import Enum) but how can I expose these to QML? I have tried to import the Q_ENUM macro from PySide2.QtCore but that didn't work.


Log in to reply