首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >放大一个QGraphicsView正在崩溃

放大一个QGraphicsView正在崩溃
EN

Stack Overflow用户
提问于 2015-10-20 07:34:11
回答 1查看 197关注 0票数 1

我有一个定制的QGraphicsScene类,我想在做一些鼠标移动时进行缩放。每当因子为>= 1.0时,缩放就能正常工作。但是当因子小于1时,它就会因为(我相信是循环)而崩溃。

下面是处理缩放和解释循环的代码:

代码语言:javascript
复制
 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;

        }

    }

知道为什么放大会立即启动功能吗?谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-21 08:09:43

我必须在缩放函数之前实现全局变量的初始化,如果这个变量是在进入mouseMoveEvent时初始化的,那么我将直接退出该函数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33230624

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档