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视图框架真是强大,这些功能,轻松调用几个接口就搞定了。

  • 相关阅读:
    Nginx 配置实例-动静分离
    nginx-轮询、权重、ip_hash 、fair模式
    nginx-负载均衡
    nginx 常用的命令和配置文件
    Nginx 的简介
    阿里云--安装nginx AND访问超时
    阿里云-docker安装redis AND(docker基本操作命令)
    阿里云-docker安装mysql
    阅读金字塔原理笔记1
    Springboot-整合redis
  • 原文地址:https://www.cnblogs.com/spplus/p/5357211.html
Copyright © 2011-2022 走看看