[PyQt] reselecting last item in a qtreewidget after a clear

Jason Rahm J.Rahm at F5.com
Thu Jul 28 05:09:22 BST 2011

I have an item in the qtreewidget that when selected displays text in another widget.  When I do a save on that text, it updates the file on the remote system and the local data file, but when the qtreeview is cleared and rebuilt, my selected item is obviously no longer selected.  How do I ensure the previously selected item is selected once I do the clear?  I think the method I need is currentItemChanged.  Here's the code I'm working with:

                def on_treeWidget_iRulesList_currentItemChanged(self, currentItem, previousItem):
                                                x = currentItem.text(0)
                                                y = previousItem.text(0)
                                                print x, y

When I first click an item, I get an error on the y = line that NoneType object has no attribute 'text'.  Once I select something else, however, I get the text I expect.  When I do a refresh of the qtreewidget list, I get the error again, only on the x = line.  Any ideas how I can fix this?  Thanks,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110728/157d4fb0/attachment.html>

More information about the PyQt mailing list