I presently have a QTreeWidget named 'treeWidget', and for the life of me, cannot figure out how to get the index value or the text of the selected treeWidget branch.
目前,我有一个名为“treeWidget”的QTreeWidget,在我的生命中,我无法找到如何获取所选treeWidget分支的索引值或文本。
self.treeWidget looks like:
User
-Inbox
-Sent
-Drafts
-Trash
自我。treeWidget看起来像:用户-收件箱-发送-草稿-垃圾
I need to know which branch is selected so I can display folders in the branch's corresponding file folder. I've been trying to understand the Qt documentation, but I'm totally stumped by the C++. And the PyQt docs don't have any examples. I've searched everywhere for three days trying to tinker and figure out the answer but keep coming up with errors.
我需要知道选择了哪个分支,以便在该分支的相应文件文件夹中显示文件夹。我一直在尝试理解Qt文档,但是我完全被c++所困扰。PyQt文档没有任何例子。我到处找了三天,试着修补一下,找出答案,但总是出错。
The closest I think I've come is something like this:
我觉得最接近的是这样的:
self.connect(self.treeWidget,SIGNAL("itemSelectionChanged()"), self.loadAllMessages) def loadAllMessages(self, folder): item = self.treeWidget.currentItem()
Do I need to setSelectionMode first or something? All help is greatly appreciated!
我需要先选择setSelectionMode还是什么?非常感谢您的帮助!
1 个解决方案
#1
1
Try This
试试这个
#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
#1
1
Try This
试试这个
#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