当前位置:网站首页>Qt | 事件系统 QEvent
Qt | 事件系统 QEvent
2022-07-24 22:52:00 【InfoQ】
前言:
- 在与用户交互时发生(比如按下鼠标:mousePressEvent);
- 系统自动发生(比如定时器事件:timerEvent);
事件的处理:
- 方法一:重新实现事件函数。例如重新实现部件的paintEvent()、mousePressEvent()等事件处理函数。这时最常用的一种方法,不过只能用来处理特定部件的特定事件。
- 例如:void paintEvent(QPaintEvent *event);
- 方法二:重新实现notify()函数。这个函数的功能非常强大,提供了完全的控制,可以在事件过滤器得到事件之前就获得它们。但是它一次只能处理一个事件。
- 方法三:向QApplication对象上安装事件过滤器。因为一个程序只有一个QApplication对象,所以这样实现的功能与使用notify()函数是相同的,优点是可以同时处理多个事件。
- 方法四:重新实现event()函数。QObject类的event()函数可以在事件到达默认的事件处理函数之前获得该事件。
- 例如:bool event(QEvent *event);
- 方法五:在对象上安装事件过滤器。使用事件过滤器可以在一个界面类中同时处理不同子部件的不同事件。
- 例如:bool eventFilter(QObject *obj, QEvent *event);
事件的传递:
- 在paintEvent()函数末尾要调用:QWidget::paintEvent(event);
- 在event()函数末尾要调用:return QWidget::event(event);
- 在eventFilter()函数末尾调用:return QWidget::eventFilter(obj, event);
边栏推荐
- ASP.NET Core 6.0 基于模型验证的数据验证
- Org.json Jsonexception: what about no value for value
- 物联网平台返回数据解析时遇到org.json.JSONException: No value for Value怎么办
- 必会面试题:1.浅拷贝和深拷贝_深拷贝
- Network Security Learning (V) DHCP
- 用VS Code搞Qt6:编译源代码与基本配置
- Some analysis of slow MySQL query
- Connector in C
- Introduction to HLS programming
- 聊聊 Redis 是如何进行请求处理
猜你喜欢

Piziheng embedded: the method of making source code into lib Library under MCU Xpress IDE and its difference with IAR and MDK

工业物联网中的时序数据

Use kettle to read the data in Excel file and store it in MySQL

生成式对抗网络的效果评估

IndexTree2D

How to propose effective solutions for high-end products? (1 methodology + 2 cases + 1 List)

From Fibonacci sequence to matrix fast power technique

ShardingSphere-数据库分库分表简介

The kettle job implementation runs a kettle conversion task every 6S

Notes of Teacher Li Hongyi's 2020 in-depth learning series 2
随机推荐
About constant modifier const
背景图和二维码合成
RichTextBox save as picture
力扣 1184. 公交站间的距离
burp从溯源到反制思路
Effect evaluation of generative countermeasure network
Financial products can reach 6%. I want to open an account to buy financial products
CA certificate production practice
P3201 [hnoi2009] dream pudding heuristic merge
PHP get thumbnails
激光雷达障碍物检测与追踪实战——cuda版欧式聚类
必会面试题:1.浅拷贝和深拷贝_深拷贝
百度网盘+Chrom插件
WPF opens external programs and activates them when needed
Shardingsphere database sub database sub table introduction
买收益百分之6的理财产品,需要开户吗?
TrinityCore魔兽世界服务器-注册网站
The tragic experience of installing scikitlearn on win764
认识复杂度和简单排序运算
On the problem that the on-board relay cannot be switched on due to insufficient power supply