[英]PyQt: get the current QTreeWidget item
我現在有一個名為'treeWidget'的QTreeWidget,對於我的生活,無法弄清楚如何獲取索引值或所選treeWidget分支的文本。
self.treeWidget看起來像:
用戶
-inbox
-Sent
-Drafts
-垃圾
我需要知道選擇了哪個分支,這樣我才能在分支的相應文件夾中顯示文件夾。 我一直在努力理解Qt文檔,但我完全被C ++困擾了。 並且PyQt文檔沒有任何示例。 我在各處搜索了三天,試圖修補並找出答案,但不斷出現錯誤。
我認為我最接近的是這樣的:
self.connect(self.treeWidget,SIGNAL("itemSelectionChanged()"), self.loadAllMessages) def loadAllMessages(self, folder): item = self.treeWidget.currentItem()
我需要首先設置setSelectionMode嗎? 非常感謝所有幫助!
嘗試這個
#remove the old way of connecting
#self.connect(self.treeWidget,SIGNAL("itemSelectionChanged()"), self.loadAllMessages)
self.treeWidget.itemSelectionChanged.connect(self.loadAllMessages)
def loadAllMessages(self, folder):
getSelected = self.treeWidget.selectedItems()
if getSelected:
baseNode = getSelected[0]
getChildNode = baseNode.text(0)
print getChildNode
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.