1

When I create my own custom QTreeView with a defined 'expanded' method, do I need to do anything special to emit the default signal? I've commented out pseudo code representing what i'm asking about. Or am I safe to do what I'm currently doing?

class JMTreeView(QtGui.QTreeView):

    changed = QtCore.Signal()

    def __init__(self):
        super(JMTreeView, self).__init__()
        self.expanded.connect(self.expanded_item)

    def expanded_item(self, event):
        print "expanded"
        # super(JMTreeView, self).expanded(event)

Similar to the way I handle when I override the 'showEvent' for a dialog, i call the 'super' at the end of the function. Do i need to add something similar to my 'expanded' method?

def showEvent(self, event):
    geom = self.frameGeometry()
    geom.moveCenter(QtGui.QCursor.pos())
    self.setGeometry(geom)
    super(Browser, self).showEvent(event)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
JokerMartini
  • 5,674
  • 9
  • 83
  • 193

1 Answers1

1

The QTreeView class does not have an expanded method. There is only an expanded signal. More to the point, the signal and slots mechanism is completely separate from the event system, so there is no parallel with overriding protected methods like showEvent.

Most of the event-handlers (like showEvent) are related to activity that originates outside of the application. They usually implement some default behaviour, but sometimes do nothing at all. They are almost always virtual methods, which means you can provide your own implementation which Qt will call instead of the default. If your re-implementation needs to keep the default behaviour (or modify it in some way), it can do so by calling the base-class implementation.

By contrast, signals always originate inside the application. There are no default handlers for them - they simply broadcast messages (like a radio beacon). It is entirely up to the listeners to decide what to do with the messages. It doesn't matter if there are never any listeners, or if the messages are never processed.

ekhumoro
  • 115,249
  • 20
  • 229
  • 336