QMetaEnum#

The QMetaEnum class provides meta-data about an enumerator. More

Synopsis#

Functions#

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description#

Use name() for the enumerator’s name. The enumerator’s keys (names of each enumerated item) are returned by key() ; use keyCount() to find the number of keys. isFlag() returns whether the enumerator is meant to be used as a flag, meaning that its values can be combined using the OR operator.

The conversion functions keyToValue() , valueToKey() , keysToValue() , and valueToKeys() allow conversion between the integer representation of an enumeration or set value and its literal representation. The scope() function returns the class scope this enumerator was declared in.

class PySide6.QtCore.QMetaEnum#
PySide6.QtCore.QMetaEnum.enumName()#
Return type:

str

Returns the enum name of the flag (without the scope).

For example, the AlignmentFlag flag has AlignmentFlag as the enum name, but Alignment as the type name. Non flag enums has the same type and enum names.

Enum names have the same scope as the type name.

See also

isValid() name()

PySide6.QtCore.QMetaEnum.isFlag()#
Return type:

bool

Returns true if this enumerator is used as a flag; otherwise returns false.

When used as flags, enumerators can be combined using the OR operator.

PySide6.QtCore.QMetaEnum.isScoped()#
Return type:

bool

Returns true if this enumerator is declared as a C++11 enum class; otherwise returns false.

PySide6.QtCore.QMetaEnum.isValid()#
Return type:

bool

Returns true if this enum is valid (has a name); otherwise returns false.

See also

name()

PySide6.QtCore.QMetaEnum.key(index)#
Parameters:

index – int

Return type:

str

Returns the key with the given index, or None if no such key exists.

PySide6.QtCore.QMetaEnum.keyCount()#
Return type:

int

Returns the number of keys.

See also

key()

PySide6.QtCore.QMetaEnum.keyToValue(key)#
Parameters:

key – str

Return type:

PyTuple

Returns the integer value of the given enumeration key, or -1 if key is not defined.

If key is not defined, *``ok`` is set to false; otherwise *``ok`` is set to true.

For flag types, use keysToValue() .

PySide6.QtCore.QMetaEnum.keysToValue(keys)#
Parameters:

keys – str

Return type:

PyTuple

Returns the value derived from combining together the values of the keys using the OR operator, or -1 if keys is not defined. Note that the strings in keys must be ‘|’-separated.

If keys is not defined, *``ok`` is set to false; otherwise *``ok`` is set to true.

PySide6.QtCore.QMetaEnum.metaType()#
Return type:

PySide6.QtCore.QMetaType

Returns the meta type of the enum.

If the QMetaObject that this enum is part of was generated with Qt 6.5 or earlier, this will be an invalid meta type.

Note

This is the meta type of the enum itself, not of its underlying integral type. You can retrieve the meta type of the underlying type of the enum using underlyingType() .

PySide6.QtCore.QMetaEnum.name()#
Return type:

str

Returns the name of the type (without the scope).

For example, the Key enumeration has Key as the type name and Qt as the scope.

For flags this returns the name of the flag type, not the name of the enum type.

PySide6.QtCore.QMetaEnum.scope()#
Return type:

str

Returns the scope this enumerator was declared in.

For example, the AlignmentFlag enumeration has Qt as the scope and AlignmentFlag as the name.

See also

name()

PySide6.QtCore.QMetaEnum.value(index)#
Parameters:

index – int

Return type:

int

Returns the value with the given index; or returns -1 if there is no such value.

PySide6.QtCore.QMetaEnum.valueToKey(value)#
Parameters:

value – int

Return type:

str

Returns the string that is used as the name of the given enumeration value, or None if value is not defined.

For flag types, use valueToKeys() .

PySide6.QtCore.QMetaEnum.valueToKeys(value)#
Parameters:

value – int

Return type:

PySide6.QtCore.QByteArray

Returns a byte array of ‘|’-separated keys that represents the given value.