【发布时间】:2015-10-20 07:34:11
【问题描述】:
我有一个自定义 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;
}
}
知道为什么缩小会立即开始功能吗?谢谢
【问题讨论】:
标签: c++ qt crash qgraphicsview qgraphicsscene