PySide6.QtCore.QMetaEnum¶
- class QMetaEnum¶
The
QMetaEnumclass provides meta-data about an enumerator.Details
Use
name()for the enumerator’s name. The enumerator’s keys (names of each enumerated item) are returned bykey(); usekeyCount()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(), andvalueToKeys()allow conversion between the integer representation of an enumeration or set value and its literal representation. Thescope()function returns the class scope this enumerator was declared in.To use
QMetaEnumfunctionality, register the enumerator within the meta-object system using theQ_ENUMmacro.enum AppleType { Big, Small }; Q_ENUM(AppleType) QMetaEnum metaEnum = QMetaEnum::fromType<ModelApple::AppleType>(); qDebug() << metaEnum.valueToKey(ModelApple::Big);
See also
Synopsis¶
Methods¶
def
__init__()def
enumName()def
is64Bit()def
isFlag()def
isScoped()def
isValid()def
key()def
keyCount()def
keyToValue()def
keysToValue()def
metaType()def
name()def
scope()def
value()def
valueToKey()def
valueToKeys()
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
- __init__()¶
- enumName()¶
- Return type:
str
Returns the enum name of the flag (without the scope).
For example, the
AlignmentFlagflag hasAlignmentFlagas the enum name, butAlignmentas the type name. Non flag enums has the same type and enum names.Enum names have the same scope as the type name.
- is64Bit()¶
- Return type:
bool
Returns
trueif the underlying type of this enumeration is 64 bits wide.See also
value64()- isFlag()¶
- Return type:
bool
Returns
trueif this enumerator is used as a flag; otherwise returns false.When used as flags, enumerators can be combined using the OR operator.
See also
- isScoped()¶
- Return type:
bool
Returns
trueif this enumerator is declared as a C++11 enum class; otherwise returns false.- isValid()¶
- Return type:
bool
Returns
trueif this enum is valid (has a name); otherwise returns false.See also
- key(index)¶
- Parameters:
index – int
- Return type:
str
Returns the key with the given
index, orNoneif no such key exists.See also
- keyCount()¶
- Return type:
int
Returns the number of keys.
See also
- keyToValue(key)¶
- Parameters:
key – str
- Return type:
PyTuple
Returns the integer value of the given enumeration
key, or -1 ifkeyis not defined.If
keyis not defined, *``ok`` is set to false; otherwise *``ok`` is set to true.For flag types, use
keysToValue().If this is a 64-bit enumeration (see
is64Bit()), this function returns the low 32-bit portion of the value. UsekeyToValue64()to obtain the full value instead.See also
keyToValue64valueToKey()isFlag()keysToValue()is64Bit()- keysToValue(keys)¶
- Parameters:
keys – str
- Return type:
PyTuple
Returns the value derived from combining together the values of the
keysusing the OR operator, or -1 ifkeysis not defined. Note that the strings inkeysmust be ‘|’-separated.If
keysis not defined, *``ok`` is set to false; otherwise *``ok`` is set to true.If this is a 64-bit enumeration (see
is64Bit()), this function returns the low 32-bit portion of the value. UsekeyToValue64()to obtain the full value instead.See also
keysToValue64()isFlag()valueToKey()valueToKeys()is64Bit()Returns the meta type of the enum.
If the
QMetaObjectthat 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().- name()¶
- Return type:
str
Returns the name of the type (without the scope).
For example, the
Keyenumeration hasKeyas 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.
See also
- scope()¶
- Return type:
str
Returns the scope this enumerator was declared in.
For example, the
AlignmentFlagenumeration hasQtas the scope andAlignmentFlagas the name.See also
- value(index)¶
- Parameters:
index – int
- Return type:
int
Returns the value with the given
index; or returns -1 if there is no such value.If this is an enumeration with a 64-bit underlying type (see
is64Bit()), this function returns the low 32-bit portion of the value. Usevalue64()to obtain the full value instead.See also
value64()keyCount()key()keyToValue()- valueToKey(value)¶
- Parameters:
value – int
- Return type:
str
Returns the string that is used as the name of the given enumeration
value, orNoneifvalueis not defined.For flag types, use
valueToKeys().See also
- valueToKeys(value)¶
- Parameters:
value – int
- Return type:
Returns a byte array of ‘|’-separated keys that represents the given
value.Note
Passing a 64-bit
valueto an enumeration whose underlying type is 32-bit (that is, ifis64Bit()returnsfalse) results in an empty string being returned.See also