[PyQt] selecting an item in qtreewidget

Jason Rahm J.Rahm at F5.com
Tue May 3 23:00:40 BST 2011


I figured out the "itemClicked part"

                def __init__(self):
self.treeWidget_iRulesList.itemClicked.connect(self.displayRule)
                def displayRule(self):
self.textEdit_ScriptCanvas.clear()
                                self.textEdit_ScriptCanvas.setText('test')

Still not sure about auto-selecting the last item added to the tree.  Any thoughts would be appreciated.

Jason

From: pyqt-bounces at riverbankcomputing.com [mailto:pyqt-bounces at riverbankcomputing.com] On Behalf Of Jason Rahm
Sent: Tuesday, May 03, 2011 2:27 PM
To: pyqt at riverbankcomputing.com
Subject: [PyQt] selecting an item in qtreewidget

Newbie question...I'm stuck on how to select an item in my qtreewidget.  This loop populates my tree:

        item = []
        for item in allrules.keys():
            hdr = QTreeWidgetItem([item])
            self.treeWidget_iRulesList.addTopLevelItem(hdr)
           self.treeWidget_iRulesList.expandItem(hdr)
            x = []
            for x in allrules[item]:
                rule = QTreeWidgetItem(hdr, [x])
                self.treeWidget_iRulesList.addTopLevelItem(rule)

        self.treeWidget_iRulesList.resizeColumnToContents(0)

This is where I'm trying to set the current item, but I'm guessing it's empty since there isn't one already set?

        selRule = self.treeWidget_iRulesList.currentItem()

How do I select the last item added, and how do I select one by clicking on it?  Sorry to be so basic, I'm really trying to understand the syntax!

Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110503/b1a77b83/attachment.html>


More information about the PyQt mailing list