def _get_pyqt_objects(lines: MutableSequence[str], obj: QObject, depth: int = 0) -> None: """Recursive method for get_all_objects to get Qt objects.""" for kid in obj.findChildren(QObject, '', Qt.FindDirectChildrenOnly): lines.append(' ' * depth + repr(kid)) _get_pyqt_objects(lines, kid, depth + 1)
def apply_font(qt_root_obj: QtCore.QObject, font_name: str): font = get_font(font_name) if not config.qt_app: return config.qt_app.setFont(font) for qt_obj in qt_root_obj.findChildren(QtWidgets.QWidget): obj_font = qt_obj.font() obj_font.setFamily(font.family())
def QObject对象名称和属性(self): obj0 = QObject() obj1 = QObject() obj2 = QObject() obj3 = QObject() obj4 = QObject() obj5 = QObject() obj2.setObjectName("2") obj3.setObjectName("3") print("obj0", obj0) print("obj1", obj1) print("obj2", obj2) print("obj3", obj3) print("obj4", obj4) print("obj5", obj5) obj1.setParent(obj0) obj2.setParent(obj0) obj3.setParent(obj1) obj4.setParent(obj2) obj5.setParent(obj2) print(obj1.parent()) print(obj2.parent()) print(obj0.children()) print(obj0.findChildren(QObject, None, Qt.FindChildrenRecursively)) print(obj0.findChild(QObject, "2", Qt.FindChildrenRecursively)) #********************内存管理***************************开始 obj1 = QObject() self.obj1 = obj1 obj2 = QObject() obj2.setParent(obj1) # 监听obj2对象被释放 obj2.destroyed.connect(lambda _: print("obj2对象被释放了")) del self.obj1