当前位置:网站首页>Qt绘制图像
Qt绘制图像
2022-04-23 12:10:00 【MechMaster】
1. 例程代码
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter;
//绘制image
QImage image(100,100,QImage::Format_ARGB32);
painter.begin(&image);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QImage"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//绘制pixmap
QPixmap pix(100,100);
painter.begin(&pix);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QPixmap"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//绘制bitmap
QBitmap bit(100,100);
painter.begin(&bit);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QBitmap"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//绘制picture
QPicture picture;
painter.begin(&picture);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QPicture"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//在widget部件上进行绘制
painter.begin(this);
painter.drawImage(50,20,image);
painter.drawPixmap(200,20,pix);
painter.drawPixmap(50,170,bit);
painter.drawPicture(200,170,picture);
}
2. 四个常用的绘图设备
2.1 QImage
- QImage主要用来进行I/O处理,它对I/O处理操作进行了优化,而且可以用来直接访问和操作像素;
2.2 QPixmap
- QPixmap主要用来在屏幕上显示图像,它对在屏幕上显示图像那个进行了优化;
2.3 QBitmap
- QBitmap 是 QPixmap 的子类,用来处理颜色深度为1的图像,即只能显示黑白两种颜色;
2.4 QPicture
- QPicture用来记录并重演QPainter命令。
3. 复合模式
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter;
QImage image(400,300,QImage::Format_ARGB32_Premultiplied);
painter.begin(&image);
painter.setBrush(Qt::green);
painter.drawRect(100,50,200,200);
painter.setBrush(QColor(0,0,255,15));
painter.drawRect(50,0,100,100);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawRect(250,0,100,100);
painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
painter.drawRect(50,200,100,100);
painter.setCompositionMode(QPainter::CompositionMode_Xor);
painter.drawRect(250,200,100,100);
painter.end();
painter.begin(this);
painter.drawImage(0,0,image);
}
版权声明
本文为[MechMaster]所创,转载请带上原文链接,感谢
https://liuhui.blog.csdn.net/article/details/124264238
边栏推荐
- C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
- 第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
- 九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
- 激活函数之relu函数
- Lesson 25 static member variables of classes
- 《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
- Database design of simple voting system
- worder字体网页字体对照表
- 软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资
- How the database fills in IM expressions (IM 5.4)
猜你喜欢
Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
1. Construction of electron development environment
IDEA 数据库插件Database Navigator 插件
Worder font page font comparison table
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资
运行报错:找不到或无法加载主类 com.xxx.Application
同态加密技术学习
IDEA 代码格式化插件Save Actions
随机推荐
第五章 使用In-Memory表达式优化查询(IM 5.1)
SQL exercise (I)
Idea code formatting plug-in save actions
How to solve the computer system card?
Running error: unable to find or load the main class com xxx. Application
thinkphp 添加图片文字水印生成带二维码的推广海报
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
Application of remote integrated monitoring system in power distribution room in 10kV prefabricated cabin project
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
传统企业如何应对数字化转型?这些书给你答案
On using go language to create websocket service
第四章 为IM 启用填充对象之启用和禁用列(IM-4.3 第三部分)
Tensorflow uses keras to create neural networks
Interpretation 3 of gdpr series: how do European subsidiaries return data to domestic parent companies?
获取钉钉考勤机打卡记录
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
数组---
第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
Purpose of IM expression (IM 5.2)
Fabric 1.0 source code analysis (33) implementation of peer channel command and subcommand