PyQt5類型判定+對象刪除操作
1、類型判定
(1)總體結(jié)構(gòu)
(2)API操作
from PyQt5.Qt import * class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle("QObject的學(xué)習(xí)") self.resize(500, 500) self.setup_ui() def setup_ui(self): #self.QObject_ceshi() self.QObject_類型判定() def QObject_類型判定(self): # # *********** 測試API**************開始 obj=QObject() w=QWidget() btn=QPushButton() label=QLabel() objs=[obj,w,btn,label] for o in objs: # print(o.isWidgetType()) # print(o.inherits('QWidget')) print(o.inherits('QPushBotton')) # *********** 測試API**************結(jié)束 if __name__ == '__main__': import sys app=QApplication(sys.argv) window=Window() window.show() sys.exit(app.exec_())
(3)案例
from PyQt5.Qt import * class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle("QObject的學(xué)習(xí)") self.resize(500, 500) self.setup_ui() def setup_ui(self): #self.QObject_ceshi() self.QObject_類型判定() def QObject_類型判定(self): # # *********** 測試API**************開始 # obj=QObject() # w=QWidget() # btn=QPushButton() # label=QLabel() # # objs=[obj,w,btn,label] # for o in objs: # # print(o.isWidgetType()) # # print(o.inherits('QWidget')) # print(o.inherits('QPushBotton')) # *********** 測試API**************結(jié)束 # **************案例*****************開始 label = QLabel(self) label.setText("社會社會社會") label.move(100, 100) label2 = QLabel(self) label2.setText("哈哈哈哈") label2.move(150, 150) btn = QPushButton(self) btn.setText("點(diǎn)我") btn.move(200, 200) for widget in self.children(): # print(widget) if widget.inherits("QLabel"): # print("是") widget.setStyleSheet('background-color:green') # **************案例*****************結(jié)束 if __name__ == '__main__': import sys app=QApplication(sys.argv) window=Window() window.show() sys.exit(app.exec_())
2、對象刪除
(1)總體框架
(2)API操作
from PyQt5.Qt import * class Window(QWidget): def __init__(self): super().__init__() self.setWindowTitle("QObject的學(xué)習(xí)") self.resize(500, 500) self.setup_ui() def setup_ui(self): #self.QObject_ceshi() self.QObject_對象刪除() def QObject_對象刪除(self): # *********** 測試API**************開始 obj1 = QObject() self.obj1=obj1 obj2 = QObject() obj3 = QObject() obj3.setParent(obj2) obj2.setParent(obj1) obj1.destroyed.connect(lambda:print("obj1被釋放了")) obj2.destroyed.connect(lambda: print("obj2被釋放了")) obj3.destroyed.connect(lambda: print("obj3被釋放了")) # del obj2 obj2.deleteLater() # 稍后刪除 print(obj1.children()) # 先完成再刪除 # *********** 測試API**************結(jié)束 if __name__ == '__main__': import sys app=QApplication(sys.argv) window=Window() window.show() sys.exit(app.exec_())
到此這篇關(guān)于PyQt5類型判定+對象刪除的文章就介紹到這了,更多相關(guān)PyQt5對象類型判定內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于Python實(shí)現(xiàn)圖像文字識別OCR工具
在工作、生活中常常會用到,比如票據(jù)、漫畫、掃描件、照片的文本提取。本文主要介紹了基于PyQt + PaddleOCR實(shí)現(xiàn)的一個桌面端的OCR工具,用于快速實(shí)現(xiàn)圖片中文本區(qū)域自動檢測+文本自動識別,需要的朋友可以參考一下2021-12-12Python中的response.text與content區(qū)別詳解
這篇文章主要介紹了Python中的response.text與content區(qū)別詳解,?從網(wǎng)絡(luò)請求下來的數(shù)據(jù),他們都是字節(jié)類型的,如果服務(wù)器不指定的話,默認(rèn)編碼是"ISO-8859-1",我們使用text直接拿到的是字符串類型,沒有進(jìn)行解碼操作,則會出現(xiàn)亂碼問題,需要的朋友可以參考下2023-12-12Python爬蟲進(jìn)階之Beautiful Soup庫詳解
這篇文章主要介紹了Python爬蟲進(jìn)階之Beautiful Soup庫詳解,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)python爬蟲的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04Python創(chuàng)建增量目錄的代碼實(shí)例
這篇文章主要給大家介紹了關(guān)于Python創(chuàng)建增量目錄的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用python具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-11-11Python Pandas數(shù)據(jù)中對時間的操作
這篇文章主要介紹了Python Pandas數(shù)據(jù)中對時間的操作,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07關(guān)于matplotlib及相關(guān)cmap參數(shù)的取值方式
這篇文章主要介紹了關(guān)于matplotlib及相關(guān)cmap參數(shù)的取值方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-11-11Python爬蟲Scrapy框架IP代理的配置與調(diào)試
在調(diào)試爬蟲的時候,新手都會遇到關(guān)于ip的錯誤,本文就來介紹一下Python爬蟲Scrapy框架IP代理的配置與調(diào)試,具有一定的參考價值,感興趣的可以了解一下2021-12-12使用scrapy ImagesPipeline爬取圖片資源的示例代碼
這篇文章主要介紹了使用scrapy ImagesPipeline爬取圖片資源的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09