Qt实用技巧:组合图形的比例变换

简介: Qt实用技巧:组合图形的比例变换

若该文为原创文章,未经允许不得转载

原博主博客地址:https://blog.csdn.net/qq21497936

原博主博客导航:https://blog.csdn.net/qq21497936/article/details/102478062

本文章博客地址:https://blog.csdn.net/qq21497936/article/details/79163130

各位读者,知识无穷而人力有穷,要么改需求,要么找专业人士,要么自己研究

红胖子(红模仿)的博文大全:开发技术集合(包含Qt实用技术、树莓派、三维、OpenCV、OpenGL、ffmpeg、OSG、单片机、软硬结合等等)持续更新中…(点击传送门)

Qt开发专栏:实用技巧(点击传送门)

 

需求

       对三个组合矩形进行比例变化,Demo实现效果如下:

 

图片.png

 

原理解说图

图片.png

 

关键代码

void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.save();
    painter.setPen(Qt::black);
    int rectx = _rectx + _dx;
    int recty = _recty + _dy;
    int rectWidth = _rectWidth/(float)_width*(_width+_dwidth);
    int rectHeight = _rectHeight/(float)_height*(_height+_dheight);
    painter.drawRect(rectx, recty, rectWidth, rectHeight);
    painter.restore();
    painter.save();
    painter.setPen(Qt::red);
    int rect2x = _rectx + _dx + (_rect2x-_rectx)/(float)_rectWidth*rectWidth;
    int rect2y = _recty + _dy + (_rect2y-_recty)/(float)_rectHeight*rectHeight;
    int rect2Width = _rect2Width/(float)_rectWidth*rectWidth;
    int rect2Height = _rect2Height/(float)_rectHeight*rectHeight;
    painter.drawRect(rect2x, rect2y, rect2Width, rect2Height);
    painter.restore();
    painter.save();
    painter.setPen(Qt::blue);
    int rect3x = _rectx + _dx + (_rect3x-_rectx)/(float)_rectWidth*rectWidth;
    int rect3y = _recty + _dy + (_rect3y-_recty)/(float)_rectHeight*rectHeight;
    int rect3Width = _rect3Width/(float)_rectWidth*rectWidth;
    int rect3Height = _rect3Height/(float)_rectHeight*rectHeight;
    painter.drawRect(rect3x, rect3y, rect3Width, rect3Height);
    painter.restore();
}

 

原博主博客地址:https://blog.csdn.net/qq21497936

原博主博客导航:https://blog.csdn.net/qq21497936/article/details/102478062

本文章博客地址:https://blog.csdn.net/qq21497936/article/details/79163130

 

相关文章
|
5月前
|
存储
QT图形视图框架绘制曲线图和Smith图
QT图形视图框架绘制曲线图和Smith图
87 0
|
5月前
|
数据可视化 图形学 开发者
【Qt 底层机制之图形渲染引擎】深入理解 Qt 的 渲染机制:从基础渲染到高级图形
【Qt 底层机制之图形渲染引擎】深入理解 Qt 的 渲染机制:从基础渲染到高级图形
811 4
|
2月前
|
XML Linux C++
【Qt】图形化和纯代码实现Hello world的比较
【Qt】图形化和纯代码实现Hello world的比较
|
4月前
|
算法 计算机视觉
【Qt&OpenCV 图像的形态学变换 morpholgyEx】
【Qt&OpenCV 图像的形态学变换 morpholgyEx】
29 0
|
11月前
|
C++
《QT从基础到进阶·二十六》绘制多个图形项(QGraphicsRectItem,QGraphicsLineItem,QGraphicsPolygonItem)
《QT从基础到进阶·二十六》绘制多个图形项(QGraphicsRectItem,QGraphicsLineItem,QGraphicsPolygonItem)
208 0
|
5月前
|
编解码 供应链 开发工具
英飞凌采用Qt图形解决方案增强Traveo T2G MCU系列,实现智能渲染技术
在竞争激烈的全球半导体市场,制造商一直在努力缩短产品上市时间。同时,他们对流畅、高分辨率图形显示器的需求也在日益增长。
|
5月前
|
数据可视化 计算机视觉
QT基础教程(图形处理)
QT基础教程(图形处理)
69 0
|
5月前
|
存储 数据可视化 测试技术
[Qt5] QGraphics图形视图框架概述(Item、Scene和View)
[Qt5] QGraphics图形视图框架概述(Item、Scene和View)
833 0
|
11月前
|
缓存
《QT从基础到进阶·二十二》QGraphicsView显示大量图形项item导致界面卡顿的解决办法
《QT从基础到进阶·二十二》QGraphicsView显示大量图形项item导致界面卡顿的解决办法
484 0
QT图形视图系统 - 使用一个项目来学习QT的图形视图框架 - 终篇
接上一篇,我们需要继续完成以下的效果; 先上个效果图:
116 0
下一篇
无影云桌面