Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll event detection in qt

Tags:

scroll

qt

mouse

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.

like image 804
Frank Avatar asked Sep 04 '12 10:09

Frank


2 Answers

void QWidget::wheelEvent(QWheelEvent* event) will be what you are after (docs here).

like image 90
cmannett85 Avatar answered Oct 16 '22 10:10

cmannett85


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();
}
like image 29
developer0hye Avatar answered Oct 16 '22 09:10

developer0hye