diff --git a/viewlib/include/GoTools/viewlib/gvView.h b/viewlib/include/GoTools/viewlib/gvView.h index 53ee55ca..41e1e5ae 100644 --- a/viewlib/include/GoTools/viewlib/gvView.h +++ b/viewlib/include/GoTools/viewlib/gvView.h @@ -199,6 +199,8 @@ public slots: /// zoom and rotate the camera. virtual void mouseMoveEvent(QMouseEvent* e); + virtual void wheelEvent(QWheelEvent* e); + virtual bool get3Dpoint(int mousex, int mousey, Vector3D &objpt); void drawOverlay(); diff --git a/viewlib/src/gvView.C b/viewlib/src/gvView.C index de795003..ef5d26d9 100644 --- a/viewlib/src/gvView.C +++ b/viewlib/src/gvView.C @@ -967,6 +967,24 @@ void gvView::mouseMoveEvent(QMouseEvent* e) updateGL(); } + +//=========================================================================== +void gvView::wheelEvent(QWheelEvent* e) +//=========================================================================== +{ + // Zoom the scene with scroll wheel + double dist = 0.0; + camera_.getDistance(dist); + + // Get the delta of the wheel, and adjust the zoom factor + int delta = -e->angleDelta().y(); // y() is typically used for vertical scrolling + double zoomFactor = 1.0 - 0.001 * delta; // Adjust the zoom speed to your preference + + camera_.setDistance(dist * zoomFactor); + + updateGL(); +} + //=========================================================================== void gvView::focusOnBox() //===========================================================================