这是事件过滤器:
bool ListenerClass::eventFilter(QObject *obj, QEvent *event) {
std::cout << "Got event type " << event->type() << std::endl;
return false;
}
这是我在构造函数中安装它的方式QScrollArea
this->listenerObj = new ListenerClass(this);
this->setAttribute(Qt::WA_Hover);
this->setAttribute(Qt::WA_NoMousePropagation, false);
this->installEventFilter(this->listenerObj);
上述过滤器通常可以工作,因为它可以拦截调整大小、悬停等事件。但是,仅当到达滚动范围的边缘时才拦截滚轮事件,而不是在整个滚动期间。
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)
在页面滚动期间如何拦截车轮事件?