当前位置:网站首页>Qt重绘事件与剪切
Qt重绘事件与剪切
2022-04-23 12:10:00 【MechMaster】
Qt绘图中的一些问题
1. 重绘事件
- 发生重绘事件的原因
- repaint() 函数或者 update() 函数被调用;
- 被隐藏的部件现在被重新显示;
- 大部分部件可以简单地重绘全部界面,但是一些绘制比较慢的部件需要进行优化而只绘制需要的区域(可以使用**QPaintEvent::region()**来获取该区域),这种速度上的优化不会影响结果。
- Qt会通过合并多个重绘事件为一个事件来加快绘制,当 update() 函数被调用多次,或者窗口系统发送了多个重绘事件时,Qt会合并这些事件为一个事件,而这个时间拥有最大的需要重绘的区域。
- **update()**函数不会立即进行重绘,要等到Qt返回住时间循环后才会进行,所以多次调用 update() 函数一般只会引起一次 paintEvent() 函数调用。
- repaint() 函数会立即调用 paintEvent() 函数来重绘部件,只有在必须立即进行重绘操作的情况下(比如在动画中),才使用repaint() 函数。
- update() 函数允许Qt优化速度和减少闪烁,但是repaint() 函数不支持这样的优化。
- 千万不要在**paintEvent()**函数中调用 update() 和 repaint()
- 下面是使界面显示比较深的颜色的代码:
setBackgroundRole(QPalette::Dark);
setAutoFillBackground(true);
2. 剪切
- QPainter 可以剪切任何的绘制操作,它可以剪切一个矩形、一个区域或者一个路径中的内容,这分别可以使用 **setClipRect()、setClipRegion()、setClipPath()**函数来实现。
- 下面代码实现了剪切一个矩形中的文字:
QPainter painter(this);
painter.setClipRect(10,0,20,10);
painter.drawText(10,10,tr("10086"));
3. 读取和写入图像
- 读取图像最简便的方法就是使用 QImage 和 QPixmap 的构造函数,或者调用 QImage::load() 和 QPixmap::load() 函数。
- Qt中的 QImageReader 类提供了一个格式无关的接口,可以从文件或者其他设备中读取图像。可以在读取图像时提供更多的控制,如使用 setScaledSize() 函数将图像以指定的大小进行读取,还可以使用 setClipRect() 读取图像的一个区域。
- QImageWriter 类用来存储图像,它支持设置图像格式的特定选项,如伽马等级、压缩等级和品质等。如果不需要设置这些选项,直接使用 QImage::save() 和 **QImagePixmap::save()**函数即可。
版权声明
本文为[MechMaster]所创,转载请带上原文链接,感谢
https://liuhui.blog.csdn.net/article/details/124288674
边栏推荐
- 用户接口和IM表达式(IM 5.6)
- 抓包整理————tcp 协议[八]
- 论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
- Castle. Dynamic proxy implements transaction unit control
- On using go language to create websocket service
- 力扣-70.爬楼梯
- 第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
- IDEA设置版权信息
- Next. JS static data generation and server-side rendering
- Purpose of IM expression (IM 5.2)
猜你喜欢
Interpretation 3 of gdpr series: how do European subsidiaries return data to domestic parent companies?
力扣-70.爬楼梯
远程桌面之终端服务器超出了最大允许连接数解决
Tips for installing MySQL service in windows11: Install / Remove of the Service denied
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
SQL exercise (I)
Here comes the detailed picture and text installation tutorial of H5 game
PSCP 基本使用
Worder font page font comparison table
随机推荐
用户接口和IM表达式(IM 5.6)
Lesson 26 static member functions of classes
Tips for installing MySQL service in windows11: Install / Remove of the Service denied
In idea Solution to the problem of garbled code in Chinese display of properties file
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
激活函数之relu函数
Master slave replication configuration of MySQL
Metalama简介4.使用Fabric操作项目或命名空间
Database design of simple voting system
传统企业如何应对数字化转型?这些书给你答案
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
Here comes the detailed picture and text installation tutorial of H5 game
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
The database navigator uses the default MySQL connection prompt: the server time zone value 'Ö Ð¹ ú±ê ×¼ ʱ ¼ ä’ is unrecognized or repres
1. Construction of electron development environment
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind
Practical data Lake iceberg lesson 30 MySQL - > iceberg, time zone problems of different clients
Im architecture: CPU architecture: SIMD vector processing (im-2.3)