PyQt(Python+Qt)學習隨筆:QTreeWidget的topLevelItemCount屬性

QTreeWidget的topLevelItemCount屬性是一個只讀屬性,用於保存樹型部件中頂層項的個數,可以通過topLevelItemCount()方法獲取屬性值,缺省值爲0。

當樹型部件中頂層項的數目變化時,topLevelItemCount自動跟隨變化。

案例:
 def initTopItems(self):
       cdriver = QtWidgets.QTreeWidgetItem(1,2,["c:\\","NTFS","10G"])
       ddriver = QtWidgets.QTreeWidgetItem(["d:\\","NTFS","20G"])
       edriver = QtWidgets.QTreeWidgetItem(["e:\\","NTFS","30G"])
       print("1.self.treeWidget.topcount=", self.treeWidget.topLevelItemCount())
       self.treeWidget.addTopLevelItem(cdriver)
       print( "2.self.treeWidget.topcount=",self.treeWidget.topLevelItemCount())
       self.treeWidget.addTopLevelItem(ddriver)
       print("3.self.treeWidget.topcount=", self.treeWidget.topLevelItemCount())
       self.treeWidget.addTopLevelItem(edriver)
       print("4.self.treeWidget.topcount=", self.treeWidget.topLevelItemCount())
案例輸出:
1.self.treeWidget.topcount= 0
2.self.treeWidget.topcount= 1
3.self.treeWidget.topcount= 2
4.self.treeWidget.topcount= 3

老猿Python,跟老猿學Python!

發佈了623 篇原創文章 · 獲贊 3419 · 訪問量 34萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章