当前位置:网站首页>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 architecture: CPU architecture: SIMD vector processing (im-2.3)
- How imeu is associated with imcu (IM 5.5)
- 编程辅助工具推荐:图片工具snipaste
- 第二十四课 经典问题解析
- Lesson 24 analysis of classical problems
- thinkphp 添加图片文字水印生成带二维码的推广海报
- Chapter 4: enable and disable im column storage for materialized view (IM 4.6)
- Chapter 4 is a tutorial on forced filling of in memory objects with IM enabled filling objects (IM 4.7)
- After a circle, I sorted out this set of interview questions..
- 第二十五课 类的静态成员变量
猜你喜欢
2022 love analysis · panoramic report of industrial Internet manufacturers
IDEA设置版权信息
AI video cloud vs narrowband HD, who is the darling of the video era
A detailed explanation of head pose estimation [collection of good articles]
NativeForMySQL 连接MySQL8 提示:1251- Client does not support authentication protocol
Step function of activation function
软件测试基础DAY2-用例执行
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
How to expand the capacity of the server in the 100 million level traffic architecture? Well written!
Application of remote integrated monitoring system in power distribution room in 10kV prefabricated cabin project
随机推荐
Chapter 4: enable and disable im column storage for materialized view (IM 4.6)
Windows11 安装MySQL服务 提示:Install/Remove of the Service Denied
Fastjson 2 来了,性能继续提升,还能再战十年
Lesson 23 temporary objects
激活函数之阶跃函数
Chapter 4 is a tutorial on forced filling of in memory objects with IM enabled filling objects (IM 4.7)
VMware virtual machines export hard disk vmdk files using esxi
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
Siri gave the most embarrassing social death moment of the year
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)
画结果图推荐网址
Practical data Lake iceberg lesson 30 MySQL - > iceberg, time zone problems of different clients
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
用户接口和IM表达式(IM 5.6)
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
IDEA 中 .properties文件的中文显示乱码问题的解决办法
PSCP 基本使用
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
SQL exercise (I)