[PyQt] event filters vs subclassing

Henning Schröder henning.schroeder at gmail.com
Tue Aug 3 16:40:30 BST 2010

On Tue, Aug 3, 2010 at 2:27 PM, Dan Halbert <halbert at halwitz.org> wrote:
> [..]
> I can either subclass QGraphicsPixmapItem to handle various mouse events, or
> do installEventFilter(). In Mark Summerfield's PyQt book (p. 304), he
> cautions against using event filters, and suggests subclassing for most
> purposes, for complexity and efficiency reasons. I cannot find a pro/con
> discussion about this choice elsewhere, either in the C++ Qt book or on the
> web.
If you try to create a event filter for some simple widget you will
see that you get a lot of events you are not interested in.
But now you have to make sure that every event is handled properly.
Because function-calls/name-lookups are relatively slow on Python your
whole program might slow down, especially if
you install event filters for several objects.
Nevertheless you need event filters sometimes.
The best solution would be if PyQt could be extended with a new
installEventFilter method which also takes an optional list with event
classes you are only interested in.


More information about the PyQt mailing list