当前位置:网站首页>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
边栏推荐
- 5-minute NLP: text to text transfer transformer (T5) unified text to text task model
- 软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资
- 科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
- Pagoda panel command line help tutorial (including resetting password)
- CGC: contractual graph clustering for community detection and tracking
- Chapter 4 is a tutorial on forced filling of in memory objects with IM enabled filling objects (IM 4.7)
- 欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
- 一文详解头部位姿估计【收藏好文】
- 画结果图推荐网址
- 魔域来了H5游戏详细图文架设教程
猜你喜欢
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
c# 设置logo图标和快捷方式的图标
Idea code quality specification plug-in sonarlint
面了一圈,整理了这套面试题。。
远程访问家里的树莓派(上)
抓包整理————tcp 协议[八]
5个免费音频素材网站,建议收藏
worder字体网页字体对照表
Force buckle - 70 climb stairs
C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
随机推荐
智能多线弹性云增加独立的IP地址,如何实现多线功能?
How to switch PHP version in Windows 2008 system
Practical data Lake iceberg lesson 30 MySQL - > iceberg, time zone problems of different clients
Xinwangda announced that the price of battery products had been increased, and the investment of "weixiaoli" exceeded 1 billion
宝塔面板命令行帮助教程(包含重置密码)
[web daily practice] eight color puzzle (float)
PSCP basic usage
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
How much does software testing help reduce program bugs?
worder字体网页字体对照表
In idea Solution to the problem of garbled code in Chinese display of properties file
Chapter 4 specifies the attribute of the inmemory column on the no inmemory table for im enabled filling objects: examples (Part IV of im-4.4)
电脑系统卡如何解决?
第五章 使用In-Memory表达式优化查询(IM 5.1)
Running error: unable to find or load the main class com xxx. Application
Symmetric encryption, certificate encryption
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
激活函数之relu函数
IDEA设置版权信息