Here is the event filter:
bool ListenerClass::eventFilter(QObject *obj, QEvent *event) {
std::cout << "Got event type " << event->type() << std::endl;
return false;
}
Here is how I have installed it in the constructor of a QScrollArea
this->listenerObj = new ListenerClass(this);
this->setAttribute(Qt::WA_Hover);
this->setAttribute(Qt::WA_NoMousePropagation, false);
this->installEventFilter(this->listenerObj);
The above filter works in general since it can intercept events like resize, hover etc. However the wheel events are intercepted only when the edge of scroll range is reached and not throughout the duration of the scroll.
Viewport position User action Output
----------------------------------------------------------
Top downwards wheel <<No output>>
Middle downwards wheel <<No output>>
Middle downwards wheel <<No output>>
Just touch bottom downwards wheel Got event type 31
Bottom (can't downwards wheel Got event type 31
scroll anymore)
How can one intercept wheel events during while the page scrolls?
When the user scrolls the viewport, events happen in the viewport()
widget of the scroll area. If the requested scrolling action is possible, the event gets accepted and doesn't propagate to the scroll area itself, so you can't detect it.
To fix this, simply install event filter to the viewport()
widget instead.