我有一个定制的QGraphicsScene类,我想在做一些鼠标移动时进行缩放。每当因子为>= 1.0时,缩放就能正常工作。但是当因子小于1时,它就会因为(我相信是循环)而崩溃。
下面是处理缩放和解释循环的代码:
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;
}
}知道为什么放大会立即启动功能吗?谢谢
发布于 2015-10-21 08:09:43
我必须在缩放函数之前实现全局变量的初始化,如果这个变量是在进入mouseMoveEvent时初始化的,那么我将直接退出该函数。
https://stackoverflow.com/questions/33230624
复制相似问题