I have a custom QGraphicsScene class that I want to scale when doing some mouse movements.
The scaling works fine whenever the factor is >= 1.0. But when the factor is smaller than one, then it crashes because of (I believe a loop).
Here is the code handing the zoom and explaining the loop:
void NodeScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
// Start of function
QPointF newCoord=event->scenePos();
if (zooming) // Zooming only set to true when using right mouse button with Alt-key pressed
{
mainView->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
// Scale the view / do the zoom
if(newCoord.x()>lastMouseCoord.x())
{
// Zoom in
mainView->scale(1.03f, 1.03f);
}
if(newCoord.x()<lastMouseCoord.x())
{
// Zoom out
mainView->scale(0.97f, 0.97f); --> Goes back to start of function and then zooming out again and then start of function... etc... until crashing
}
lastMouseCoord=newCoord;
}
}
Any idea why zooming out is going to start of function immediately ? Thanks