2015-10-20 29 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時被初始化,那麼我會直接退出這個函數。