I’m confused about when you can use event()
vs. eventFilter()
to modify a widget’s behaviour.
Two examples:
A Pushbutton where you can disable tooltips without changing the tooltip text:
class PButton(QPushButton):
def __init__(self, *args):
super().__init__(*args)
self.tt_enabled = False
def event(self, event: QEvent):
if event.type() == QEvent.Type.ToolTip and not self.tt_enabled:
return True
return super().event(event)
A Delegate that doesn’t close the editor when pressing Return or Enter:
class Delegate(QStyledItemDelegate):
def eventFilter(self, obj, event: QEvent):
if event.type() == QEvent.Type.KeyPress and event.key() in (0x01000004, 0x01000005): # Return, Enter
return False
return super().eventFilter(obj, event)
Both examples work as intended but one uses event()
and the other uses eventFilter()
, and it doesn’t work when you switch it around: use event()
on the delegate and eventFilter()
on the Pushbutton.
What’s the difference?
I’ve read the docs on The Event System, eventFilter(), and event(), but did not find an answer there.