Image Zoom in And Zoom Out Using Mouse Scroll
-
Currently, I use the class as below and promote it to graphics view to Zoom in and zoom out image, But I want to stop zoom out when the resolution of image equals the original resolution of image and I want to use press and hold scroll mouse to move picture when the resolution of image bigger than original resolution of image instead of use left mouse. this is my code:
#include "custom_view.h" Custom_View::Custom_View(QWidget *parent) : QGraphicsView(parent) { } void Custom_View::wheelEvent(QWheelEvent *_wheelEvent) { setTransformationAnchor(AnchorUnderMouse); setDragMode(ScrollHandDrag); double scaleFactor = 1.2; if (_wheelEvent->delta()>0){ scale(scaleFactor,scaleFactor); } else { scale(1/scaleFactor,1/scaleFactor); } }
I am a newbie, Please help me. Thank you so much.