[Python] Is there any way to obtain a listing of enum names and values in a typedef for QFlags?

Discussão em 'Python' iniciado por Stack, Junho 28, 2025.

  1. Stack

    Stack Membro Participativo

    Here's an example of what I mean:

    https://doc.qt.io/qt-6/qt.html#Orientation-enum

    What it says there is


    "The Orientations type is a typedef for QFlags. It stores an OR combination of Orientation values."
    ​

    What I'm trying to obtain (automatically, programmatically) is a dict like this:

    {
    "Horizontal": 1,
    "Vertical": 2
    }


    ... with a view to giving a "readable" representation of the result which delivers a value of this Orientation enum.

    ... obviously these values are a subset of "generic" values from an enormous list of QtCore.Qt constants, with values which are often int, often equal to 1 or to 2, and often ored together to produce binary values as results. This Orientation enum appears to be used in many contexts. In my particular case, I want to find the result of QSizePolicy.expandingDirections(), which returns a value in this Orientation enum.

    I have tried exploring both the Qt.Orientation enum class and the Qt.Orientations "flags" class, i.e. I've looked at dir(Qt.Orientation), etc.

    Usually dir on an enum class will show all the possible constant values. Not in this case. Is there any way of obtaining them?

    Continue reading...

Compartilhe esta Página