pyqt 遍历QTreeWidget节点
最近在写UI界面相关的东西,遇到了遍历TreeWidget节点的问题,上网搜了很多之后发现,都是Qt语言的,C++语句,使用python来写的文章找了半天没找到,于是就自己写了一个。
def traverse(self):
"""遍历节点"""
n = self.treeWidget.topLevelItemCount() #获取根节点数量
for i in range(0, n):
item = self.treeWidget.topLevelItem(i) #循环获取根节点
text = item.text(0) #根节点文字信息(默认一列)
count = item.childCount() #获取当前根节点的子节点数量
if count != 0:
for j in range(0, count):
string = item.child(j).text(0) #子节点的文字信息