1

How can I add an additional function to take place when an item is expanded? Below I've attempted to re-implement the expandItem event but it doesn't appear to do anything. Why is that?

# QTreeWidgets
# ------------------------------------------------------------------------------
class FactionsTreeWidget( QtGui.QTreeWidget ):
    def __init__(self, parent=None):
        QtGui.QTreeWidget.__init__(self, parent)
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.setItemsExpandable(True)
        self.setAlternatingRowColors(True)

    def itemExpanded( self, *args, **kwargs ):
        res = super( self, my_class ).itemExpanded( *args, **kwargs )
        print "expanding stuff..."
        return res

1 Answer 1

2

itemExpanded is a signal emitted by QTreeWidget, not one of it's method. So you just need to connect this signal to your function.

    ...
    self.itemExpanded.connect(self.onItemExpanded)

def onItemExpanded(self,item):
    print("stuff")
Sign up to request clarification or add additional context in comments.

1 Comment

thank you. im not super familiar with this language so i appreciate the help and explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.