Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Zoom problem in QGraphicsView



  • 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:

    1. I do zoom in in the image.
    2. I move the mouse cursor position.
    3. 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!!


Log in to reply