Have a look at QObject::installEventFilter().