其他分享
首页 > 其他分享> > PyQt5 QObject-对象父类、子类设置和查找

PyQt5 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_())

 

标签:__,obj1,obj2,子类,self,PyQt5,QObject,print
来源: https://www.cnblogs.com/lvdongjie/p/16330751.html