QT界面,鼠标滚轮实现缩放问题

来源:互联网 发布:app数据接口怎么写 编辑:程序博客网 时间:2024/04/30 03:18

Fr: QT界面,鼠标滚轮实现缩放问题


1、实现放大与缩小接口:

//发生缩放
    if(scaling_flag == 1)
    {
        Video->setScaledContents(false);
        //fprintf(stderr,"__________________________%f\n",m_scaling);
         //QImage: out of memory, returning null image
//        QImage* imgScaled = new QImage;
//        *imgScaled=mge.scaled(mge.width()*m_scaling,
//                             mge.height()*m_scaling,
//                             Qt::KeepAspectRatio);
//        mge = *imgScaled;

        //解决图片过大,出现内存溢出
        mge = mge.scaled(mge.width()*m_scaling,
                             mge.height()*m_scaling,
                             Qt::KeepAspectRatio);
        //fprintf(stderr,"----------------------------------%d,%d\n",mge.width(),mge.widthMM());
        //解决图像中心缩放
        if(mge.width()>Video->width())
        {
            mge = mge.copy((mge.width()-Video->width())/2,(mge.height()-Video->height())/2,
                           Video->width(),Video->height());
        }

    }


2 Qt编程之通过鼠标滚轮事件缩放QGraphicsView里面的Item

QT类之事件mousePressEvent以及mouseMoveEvent



原创粉丝点击