How do I detect a scroll event in a Qt widget?.
I want to use it to scroll a QWT plot. I have tried using a QMouseEvent
, but I could only find options for movement and pressing/releasing the mouse.
void QWidget::wheelEvent(QWheelEvent* event)
will be what you are after (docs here).
If you use vertical wheel mouse, you can catch wheel up or wheel down event using the below function. If you use horizontal wheel mouse, check ev->angleDelta().x()
value!
void wheelEvent(QWheelEvent *ev)
{
if(ev->angleDelta().y() > 0) // up Wheel
action1();
else if(ev->angleDelta().y() < 0) //down Wheel
action2();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With