2015-10-20 32 views
1

我有一个自定义的QGraphicsScene类,我想在缩放时做一些鼠标移动。 只要系数> = 1.0,缩放就能正常工作。但是当这个因子小于1时,它会因为(我相信一个循环)而崩溃。
这里是代码交给变焦和解释循环:缩小QGraphicsView崩溃

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; 

     } 

    } 

任何想法,为什么缩小是要立即启动的功能?谢谢

回答

0

我不得不在zoomout函数前实现一个全局变量的初始化,并且如果这个变量在进入mouseMoveEvent时被初始化,那么我会直接退出这个函数。