Zoom problem in QGraphicsView
Solved
General and Desktop
-
Hello!
I am trying to develope the zoom function in a QGraphicsView.
I have this code:
double scaleFactor = 1.15; double currentScale = 1.0; double scaleMin = 1.00; void imageView::wheelEvent(QWheelEvent *event) { /* MODO POR DEFECTO (ZOOM) ****************************************************************************** */ if (graphicMode == ZOOM_MODE) { //if (sceneMode == NoMode) { this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse); if (event->delta() > 0) { this->scale(scaleFactor, scaleFactor); currentScale *= scaleFactor; } else if (currentScale > scaleMin && (currentScale / scaleFactor) >= scaleMin ) { this->scale(1/scaleFactor, 1/scaleFactor); currentScale /= scaleFactor; } else if (currentScale <= scaleMin) { //currentScale = scaleMin; } this->centerOn(event->pos()); _pan = false; } /* ****************************************************************************************************** */ }
I have a problem with this sequence:
- I do zoom in in the image.
- I move the mouse cursor position.
- When I do zoom out, the zoom doesn't do it correctly. The position of the zoom out isn't correct.
What could be the mistake?
Thank you very much!!