PyQt(Python+Qt)學習隨筆:QTabWidget選項卡部件當前項類屬性currentIndex、currentTabText、currentTabName、currentTabIcon介紹


QTabWidget的當前項類屬性為用於訪問當前操作的選項卡,包括如下屬性:

1. currentIndex當前選項的位置索引
如果沒有選擇當前項,currentIndex值為-1,可以通過方法currentIndex()和setCurrentIndex(int index)訪問該屬性。當前項變化時,選項卡部件會發射currentChanged(int index)信號。

2. currentTabText當前項文本
currentTabText為當前選項卡欄的文本,但實際上QTabWidget並沒有該屬性,該屬性的訪問實際上就是對當前選項卡的tabText的訪問。要訪問當前選項卡的文本,需要通過currentIndex()方法去訪問該選項卡的tabText屬性。訪問示例代碼如下:

print(self.tabWidget.tabText(self.tabWidget.currentIndex()))
self.tabWidget.setTabText(self.tabWidget.currentIndex(),  "新冠肺炎的表現特征")

3. currentTabName當前項名稱
currentTabName為當前選項卡的名字,但實際上QTabWidget並沒有該屬性,該屬性的訪問實際上就是對選項卡的currentWidget()的返回值的objectName的訪問。訪問的示例代碼如下:

		currentTab = self.tabWidget.currentWidget()
        print(currentTab.objectName())
        currentTab.setObjectName('ObjectNametest')

4. currentTabIcon當前項圖標
currentTabIcon為當前選項卡欄的圖標,但實際上QTabWidget並沒有該屬性,該屬性的訪問實際上就是對選項卡的tabIcon屬性的訪問。要訪問當前選項卡的圖標,需要通過currentIndex去訪問該選項卡的tabIcon。訪問示例代碼如下:

print(self.tabWidget.tabIcon(self.tabWidget.currentIndex()))
self.tabWidget.setTabIcon(self.tabWidget.currentIndex(),  QtGui.QPixmap(":/IT/圖像文件/1.png"))

5. currentTabToolTip當前項工具欄提示
currentTabToolTip為當前選項卡欄的工具欄提示,但實際上QTabWidget並沒有該屬性,該屬性的訪問實際上就是對選項卡的tabToolTip屬性的訪問。要訪問當前選項卡的toolTip,需要通過currentIndex去訪問該選項卡的tabToolTip。訪問示例代碼如下:

index = self.tabWidget.currentIndex()
print(self.tabWidget.tabToolTip(index ))
self.tabWidget.setTabToolTip(self.tabWidget.currentIndex(),  '選項卡'+str(index))

6. currentTabWhatsThis當前項幫助信息
currentTabWhatsThis為當前選項卡欄的幫助提示信息,但實際上QTabWidget並沒有該屬性,該屬性的訪問實際上就是對選項卡的tabWhatsThis屬性的訪問。要訪問當前選項卡的tabWhatsThis,需要通過currentIndex去訪問該選項卡的tabWhatsThis。訪問示例代碼如下:

index = self.tabWidget.currentIndex()
print(self.tabWidget.tabWhatsThis(index ))
self.tabWidget.setTabWhatsThis(self.tabWidget.currentIndex(),  '幫助信息'+str(index))

老猿Python,跟老猿學Python!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM