zoukankan      html  css  js  c++  java
  • 实现图形的整体移动、放大、缩小

    目前加载一副svg图形已经完成,并且已经把svg图形解析成item对象。下一步需要实现整幅图形的移动、放大、缩小。

    一:实现放大缩小功能:

    通过QGraphicsView的scale方法,实现整view的放大缩小:

    void GraphicsView::zoomOut()
    {
    
        m_scale += m_interal;
        QMatrix oldMatrix = this->matrix();
        this->resetMatrix();
        this->translate(oldMatrix.dx(), oldMatrix.dy());
        this->scale(m_scale, m_scale);
    }
    
    void GraphicsView::zoomIn()
    {
        m_scale -= m_interal;
    
        QMatrix oldMatrix = this->matrix();
        this->resetMatrix();
        this->translate(oldMatrix.dx(), oldMatrix.dy());
        this->scale(m_scale, m_scale);
    }
    
    void GraphicsView::zoomHome()
    {
        m_scale = 1.0;
    
        QMatrix oldMatrix = this->matrix();
        this->resetMatrix();
        this->translate(oldMatrix.dx(), oldMatrix.dy());
        this->scale(m_scale, m_scale);
        
    }

    二:实现增幅图形拖动功能

    void MainWindow::setViewModel()
    {
        QGraphicsView::DragMode md;
        QIcon icon;
        if (m_viewModelAction->data().toInt() == QGraphicsView::NoDrag)
        {
            md = QGraphicsView::ScrollHandDrag;
            m_viewModelAction->setIcon(QIcon(":images/hand.png"));
        }
        else
        {
            md = QGraphicsView::NoDrag;
            m_viewModelAction->setIcon(QIcon(":images/pointer.png"));
        }
        m_viewModelAction->setData(md);
        m_view->setDragMode(md);
    }

    通过设置QGraphicsview的拖拽方式,轻松实现。支持两种拖拽模式:

    1.橡皮筋拖拽选择

    该拖拽模式是否通过鼠标进行拖拽多选,绘图的时候适合。

    2.滚动拖拽选择

    该多种模式是整幅图形移动,适合浏览图形。

    QT视图框架真是强大,这些功能,轻松调用几个接口就搞定了。

  • 相关阅读:
    php对接网易云信视频直播
    python基础--1.数据操作
    pytest自动化7:assert断言
    pytest自动化6:pytest.mark.parametrize装饰器--测试用例参数化
    pytest自动化5:pytest-html插件--生成html报告
    pytest自动化4:fixture之yield实现teardown
    pytest自动化3:fixture之conftest.py实现setup
    pytest自动化2:测试用例setup和teardown
    pytest自动化1:兼容unittest代码实例
    排序
  • 原文地址:https://www.cnblogs.com/spplus/p/5357211.html
Copyright © 2011-2022 走看看