[英]How to get Qt widget type
a = QtGui.QLineEdit()
Is there a way to query what Qt widget the variable a
is? 有没有办法查询变量
a
是什么Qt小部件? It appears some Qt widgets would be supplied with .uiType
attribute. 似乎某些Qt小部件将提供
.uiType
属性。 But some (like layouts) are not. 但是有些(如布局)则不是。
You can get the type of any object in Python using the type
built-in : 您可以使用内置类型获取Python中任何对象的
type
:
print type(a)
You may also be interested in the __name__
and __class__
attributes, which will hold data corresponding to the widget's name and class: 您可能还对
__name__
和__class__
属性感兴趣,这些属性将保存与小部件的名称和类相对应的数据:
type(a).__name__ # Returns class name as a string
a.__class__ # Same as type(a)
Note however that if you need to perform a typecheck , you should use isinstance
: 但是请注意,如果你需要执行一个类型检测 ,你应该使用
isinstance
:
isinstance(a, type_to_test_for)
This will take into account inheritance. 这将考虑继承。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.