1、
2、先学习父类,在学习子类拥有的特性。
3、QObject基类(所有对象的基类);QWidget是所有可视化控件的基类。
4、QObject功能测试:
from PyQt5.Qt import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QObject学习")
self.resize(500,500)
self.setup_ui()
def setup_ui(self):
self.QObject_structure_test(self)
def QObject_structure_test(self):
#QObject.__subclasses__()
# 获取他的父类
mros = QObject.mro()
for mro in mros:
print(mro)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
5、QObject对象名称和属性API
对象,属性:API
from PyQt5.Qt import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("QObject学习")
self.resize(500,500)
self.setup_ui()
def setup_ui(self):
#self.QObject_structure_test(self)
self.QObject_name_property()
def QObject_structure_test(self):
#QObject.__subclasses__()
# 获取他的父类
mros = QObject.mro()
for mro in mros:
print(mro)
def QObject_name_property(self):
# 测试API
obj = QObject()
obj.setObjectName("notice")
print(obj.objectName)
obj.setProperty("notice_level", "error")
obj.setProperty("notice_level2", "warning")
print(obj.property("notice_level"))
print(obj.dynamicPropertyNames())
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())