物件的父子關係API

2022-06-25 12:54:15 字數 1550 閱讀 4292

parent() 獲取父物件

setparent() 設定父物件

chirldren() 獲取子物件(包含多個)

findchild() 查詢子物件,若有多個子物件符合查詢條件,找到第乙個符合條件的子物件就返回,即即使有多個子物件符合,但只返回乙個子物件

findchildren() 查詢子物件,若有多個子物件符合查詢條件,則返回所有符合條件的子物件,查詢範圍為直接子物件和間接子物件

使用示例

#

-*- coding: utf-8 -*-

from pyqt5.qt import *obj0 =qobject()

obj1 =qobject()

obj2 =qobject()

obj3 =qobject()

obj4 =qobject()

obj5 =qobject()

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(obj4.parent()) #

返回obj4的父物件obj2,不返回obj0

print(obj0.children()) #

返回obj0的子物件obj1和obj2,不返回它們各自的子物件

obj1.setparent(obj2)

print(obj1.parent()) #

返回obj1新的父物件obj2,obj0已不是父物件

obj1.setparent(obj0) #

將obj1的父物件重新設定為obj0

print(obj0.findchild(qobject)) #

返回obj0的qobject型別的子物件,只返回查到的乙個直接子物件

print(obj0.findchild(qobject, '

5')) #

返回obj0的qobject型別且objectname是5的子物件,該子物件也可以是obj0的間接子物件

print(obj0.findchild(qobject, '

5',qt.finddirectchildrenonly)) #

返回obj0的qobject型別且objectname是5的子物件,該子物件只能是obj0的直接子物件

print(obj0.findchildren(qobject)) #

返回obj0的qobject型別的子物件,返回所有查到的直接子物件

iOS 父子關係

運用自定義系統的類 自定義乙個父類,實現相同的方法 如果說乙個控制項隱藏時,他裡面的子控制項也跟著隱藏 如果說乙個控制項透明時,它裡面的子控制項也跟著透明 當子控制項超出父控制項範圍時,是可以顯示的 clipstobounds屬性 但預設是不能接受事件 把乙個控制項新增到自己的superview上時...

父子關係的設計方式

例子1 頂層父類id 12345 二級id及父id 6,1 7,1 8,2 這是兩個屬性,乙個id,乙個pid id及父類id 9,6 10,6 11,7 這個是兩個屬性,乙個id,乙個pid 四級.例子2 頂層父類id 12345 二級id及父id 6 1 7 1 8 2 這是兩個屬性,乙個id,...

檢視外來鍵父子關係

select uc.constraint name,uc.owner child owner,uc.table name child table,ucc.column name child column ucp.owner parent owner,ucp.table name parent tab...