当前位置:网站首页>QT redraw events and cuts
QT redraw events and cuts
2022-04-23 12:15:00 【MechMaster】
Qt Some problems in drawing
1. Redraw events
- The reason for the redrawing event
- repaint() Function or update() Function called ;
- Hidden parts are now redisplayed ;
- Most components can simply redraw the entire interface , However, some parts that are slow to draw need to be optimized and only the needed areas need to be drawn ( have access to **QPaintEvent::region()** To get the area ), This speed optimization does not affect the results .
- Qt It will speed up drawing by merging multiple redrawing events into one event , When update() The function is called many times , Or when the window system sends multiple redrawing Events ,Qt These events will be merged into one event , And this time has the largest area that needs to be redrawn .
- **update()** The function does not redraw immediately , Wait until the Qt Only after returning to the dwell time cycle , So multiple calls update() Functions usually cause only one paintEvent() Function call .
- repaint() The function immediately calls paintEvent() Function to redraw parts , Only if you must redraw immediately ( For example, in animation ), Only use repaint() function .
- update() Function allows Qt Optimize speed and reduce flicker , however repaint() Functions don't support such optimizations .
- Never in **paintEvent()** Call in function update() and repaint()
- Here is the code to make the interface display darker colors :
setBackgroundRole(QPalette::Dark);
setAutoFillBackground(true);
2. shear
- QPainter You can cut any drawing operation , It can cut a rectangle 、 Content in an area or a path , This can be used separately **setClipRect()、setClipRegion()、setClipPath()** Function to implement .
- The following code cuts the text in a rectangle :
QPainter painter(this);
painter.setClipRect(10,0,20,10);
painter.drawText(10,10,tr("10086"));
3. Reading and writing images
- The easiest way to read an image is to use QImage and QPixmap Constructor for , Or call QImage::load() and QPixmap::load() function .
- Qt Medium QImageReader Class provides a format independent interface , You can read images from files or other devices . More control can be provided when reading images , If you use setScaledSize() Function to read the image in the specified size , You can also use setClipRect() Read an area of the image .
- QImageWriter Class is used to store images , It supports specific options for formatting images , Such as gamma level 、 Compression grade and quality, etc . If you don't need to set these options , Use it directly QImage::save() and **QImagePixmap::save()** Function .
版权声明
本文为[MechMaster]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231210423886.html
边栏推荐
猜你喜欢
SQL exercise (I)
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
Interpretation 3 of gdpr series: how do European subsidiaries return data to domestic parent companies?
软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资
Force buckle - 70 climb stairs
Basic software testing Day2 - Case Execution
IDEA 代码质量规范插件SonarLint
激活函数之relu函数
Pagoda panel command line help tutorial (including resetting password)
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
随机推荐
1. Construction of electron development environment
[redis series] redis learning 13. Redis often asks simple interview questions
PSCP basic usage
同态加密技术学习
The listing of saiweidian Technology Innovation Board broke: a decrease of 26% and the market value of the company was 4.4 billion
Purpose of IM expression (IM 5.2)
宝塔面板命令行帮助教程(包含重置密码)
Symmetric encryption, certificate encryption
外包干了五年,废了...
初探 Lambda Powertools TypeScript
Castle.DynamicProxy实现事务单元控制
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
为什么要有包装类,顺便说一说基本数据类型、包装类、String类该如何转换?
Force buckle - 1137 Nth teponacci number
论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
Why is there a wrapper class? By the way, how to convert basic data types, wrapper classes and string classes?
获取钉钉考勤机打卡记录
第四章 为IM 启用填充对象之启用和禁用列(IM-4.3 第三部分)
SQL exercise (I)
【Redis 系列】redis 学习十三,Redis 常问简单面试题