当前位置:网站首页>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
边栏推荐
- C set Logo Icon and shortcut icon
- Lesson 24 analysis of classical problems
- 第四章 为IM 启用填充对象之强制填充In-Memory对象:教程(IM 4.7)
- Chapter 4 is a tutorial on forced filling of in memory objects with IM enabled filling objects (IM 4.7)
- 远程桌面之终端服务器超出了最大允许连接数解决
- Docker MySQL master-slave backup
- 论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
- Next. JS static data generation and server-side rendering
- 5-minute NLP: text to text transfer transformer (T5) unified text to text task model
- IMEU如何与IMCU相关联(IM 5.5)
猜你喜欢
Idea database navigator plug-in
如果你是一个Golang面试官,你会问哪些问题?
程序员如何用130行代码敲定核酸统计
编程辅助工具推荐:图片工具snipaste
CGC: contractual graph clustering for community detection and tracking
2022 love analysis · panoramic report of industrial Internet manufacturers
Share two practical shell scripts
Pagoda panel command line help tutorial (including resetting password)
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
随机推荐
C# F23. Stringsimilarity Library: String repeatability, text similarity, anti plagiarism
Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
How do programmers finalize nucleic acid statistics with 130 lines of code
AI video cloud vs narrowband HD, who is the darling of the video era
ImportError: libX11. so. 6: cannot open shared object file: No such file or directory
使用连接组优化连接 (IM 6)
第四章 为IM 启用填充对象之为IM列存储启用ADO(IM 4.8)
Relu function of activation function
第四章 为IM 启用填充对象之启用和禁用表空间的IM列存储(IM 4.5)
5个免费音频素材网站,建议收藏
Tclerror: no display name and no $display environment variable
How to switch PHP version in Windows 2008 system
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Lesson 26 static member functions of classes
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
How to expand the capacity of the server in the 100 million level traffic architecture? Well written!
On lambda powertools typescript
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
IDEA 数据库插件Database Navigator 插件
Lesson 24 analysis of classical problems