【问题标题】:Zooming out a QGraphicsView is crashing缩小 QGraphicsView 崩溃
【发布时间】: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


    【解决方案1】:

    我必须在zoomout函数之前实现一个全局变量的初始化,如果这个变量在进入mouseMoveEvent的时候被初始化了,那我就直接退出函数了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2011-08-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多