aadhithyan
aadhithyan

Reputation: 49

Zoom in / Zoom out in QT without using scroll button

I want to zoom in/out a part in openGL using mouse. Now I can do it well using the scroll button in mouse. But my goal is now to perform the same operation by holding the left mouse button and moving the mouse to and fro in the screen.

I don't know how to perform the zooming action by detecting the to and fro motion of mouse.

// function for mouse scroll events
void VDUI_GLWidget::wheelEvent (QWheelEvent * e) {
    // here comes the code for zoom in / out based on the scrolling
   MouseWheel (e->delta () / float (WHEEL_STEP), QTWheel2VCG (e->modifiers ()));
   updateGL();
}

Now I want to perform the same using mouse move and mouse press events. I'm unable to pick the event which detects the to and fro motion

Upvotes: 1

Views: 1812

Answers (1)

aadhithyan
aadhithyan

Reputation: 49

Now I have found the solution. Finding the difference between the current & previous Y axis position, I can zoom in / out the Please refer this below mentioned code.

    // function for mouse move events
    void GLWidget::mouseMoveEvent (QMouseEvent * e) {
        static int curY = 0, prevY = 0;
        if (e->buttons()) {
            curY = e->y(); // current position of Y
            if( (curY - prevY) > 0 ) // call zoom in function
            else // call zoom out function
            updateGL();
        }
        prevY = curY;
    }

Upvotes: 1

Related Questions