Python GUI编程网 > QObject基类使用教程 > QObject-对象父类、子类设置和查找
python教程

QObject-对象父类、子类设置和查找

发布日期:2020年11月23日 06:58
阅读:7286
作者:Python GUI编程网

QObject-对象父类、子类设置和查找

00:00 / 01:23
1x
2x
1.5x
1.25x
1x
0.8x
0.5x

QObject-对象父类、子类设置和查找

'''
        obj1.setParent(obj2)  # 设置父对象
        obj3.setParent(obj1)  #
        print(obj1.parent())  # 获取父对象
        print(obj2.children())
        print(obj2.findChild(QObject))   # 获取直接的子对象
        print(obj2.findChildren(QObject))   # 获取所有的子对象
'''

################################
# PyQt5中文网 - PyQt5全套视频教程 #
#    https://www.PyQt5.cn/     #
#         主讲: 村长            #
################################

from PyQt5.Qt import *
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("父子关系")
        self.resize(600,500)
        self.func_list()

    def func_list(self):
        self.func()


    def func(self):
        obj1 =QObject()
        print('obj1',obj1)
        obj2 =QObject()
        print('obj2', obj2)
        obj3 =QObject()
        print('obj3', obj3)
        obj2.setParent(obj1)
        obj3.setParent(obj2)
        print(obj2.parent())
        print(obj2.children())

        print(obj1.findChild(QObject))
        print(obj1.findChildren(QObject))




if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Window()

    window.show()
    sys.exit(app.exec_())