PySide6.QtCore.QMetaEnum¶
- class QMetaEnum¶
-
概要¶
方法¶
def
__init__()
def
enumName()
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()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
使用
name()
获取枚举器的名称。枚举器的键(每个枚举项的名称)由key()
返回;使用keyCount()
查找键的数量。isFlag()
返回枚举器是否用作标志,意味着其值可以使用OR运算符组合。转换函数
keyToValue()
、valueToKey()
、keysToValue()
和valueToKeys()
允许在枚举或集合值的整数表示与其字面表示之间进行转换。scope()
函数返回此枚举器声明的类范围。- __init__()¶
- enumName()¶
- Return type:
字符串
返回标志的枚举名称(不带范围)。
例如,
AlignmentFlag
标志的枚举名称为AlignmentFlag
,但类型名称为Alignment
。非标志枚举的类型名称和枚举名称相同。枚举名称与类型名称具有相同的作用域。
- isFlag()¶
- Return type:
布尔
如果此枚举器用作标志,则返回
true
;否则返回false。当用作标志时,枚举器可以使用 OR 运算符进行组合。
- isScoped()¶
- Return type:
布尔
如果此枚举器被声明为C++11枚举类,则返回
true
;否则返回false。- isValid()¶
- Return type:
布尔
如果此枚举有效(具有名称),则返回
true
;否则返回false。另请参阅
- key(index)¶
- Parameters:
索引 – int
- Return type:
字符串
返回给定
index
的键,如果不存在这样的键,则返回None
。- keyCount()¶
- Return type:
整数
返回键的数量。
另请参阅
- keyToValue(key)¶
- Parameters:
key – str
- Return type:
PyTuple
返回给定枚举
key
的整数值,如果key
未定义,则返回-1。如果
key
未定义,*``ok`` 设置为 false;否则 *``ok`` 设置为 true。对于标志类型,使用
keysToValue()
。- keysToValue(keys)¶
- Parameters:
keys – 字符串
- Return type:
PyTuple
返回使用 OR 运算符将
keys
的值组合在一起得到的值,如果keys
未定义,则返回 -1。请注意,keys
中的字符串必须用 '|' 分隔。如果
keys
未定义,*``ok`` 设置为 false;否则 *``ok`` 设置为 true。返回枚举的元类型。
如果这个枚举所属的
QMetaObject
是用Qt 6.5或更早版本生成的,这将是一个无效的元类型。注意
这是枚举本身的元类型,而不是其基础整数类型的元类型。您可以使用
underlyingType()
来检索枚举基础类型的元类型。- name()¶
- Return type:
字符串
返回类型的名称(不包括范围)。
例如,
Key
枚举类型具有Key
作为类型名称,并且 Qt 作为作用域。对于标志,这将返回标志类型的名称,而不是枚举类型的名称。
另请参阅
- scope()¶
- Return type:
字符串
返回此枚举器声明的范围。
例如,
AlignmentFlag
枚举以Qt
作为作用域,以AlignmentFlag
作为名称。另请参阅
- value(index)¶
- Parameters:
索引 – int
- Return type:
整数
返回给定
index
的值;如果没有这样的值,则返回-1。另请参阅
- valueToKey(value)¶
- Parameters:
值 – int
- Return type:
字符串
返回用作给定枚举
value
名称的字符串,如果value
未定义,则返回None
。对于标志类型,使用
valueToKeys()
。另请参阅
- valueToKeys(value)¶
- Parameters:
值 – int
- Return type:
返回一个由‘|’分隔的键的字节数组,表示给定的
value
。