当前位置:网站首页>Qt | 关于如何使用事件过滤器 eventFilter
Qt | 关于如何使用事件过滤器 eventFilter
2022-07-26 09:06:00 【InfoQ】
前言:
使用方法:
- bool eventFilter(QObject *obj, QEvent *event);
bool Widget::eventFilter(QObject *obj, QEvent event)
{
if(obj == ui->textEdit)
{
if(event->type == QEvent::Wheel){
return true;
}
else{
return false;
}
}
else{
return QWidget::eventFilter(obj, event);
}
}
为什么要使用过滤器:
发送事件:
- bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event);
- void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
sendEvent和postEvent的区别:
- sendEvent()会立即处理给定的事件;而postEvent()则会将事件放到等待调度队列中,当下一次Qt的主事件循环运行时才会处理它。
- sendEvent()中的QEvent队形参数在事件发送完成后无法自动删除,所以需要在栈上创建QEvent对象;而postEvent()中的QEvent对象参数必须在堆上进行创建(例如使用new),当事件被发送后事件队列会自动删除它。
QKeyEvent myEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModify);
qApp->sendEvent(ui->spinBox, &myEvent);//发送键盘事件到spinbox部件
边栏推荐
- Store a group of positive and negative numbers respectively, and count the number of 0 -- assembly language implementation
- JDBC database connection pool (Druid Technology)
- Canal 的学习笔记
- Database operation skills 6
- PAT 甲级 A1076 Forwards on Weibo
- 力扣题DFS
- 李沐d2l(四)---Softmax回归
- [leetcode database 1050] actors and directors who have cooperated at least three times (simple question)
- 网络安全漫山遍野的高大上名词之后的攻防策略本质
- mysql函数
猜你喜欢

CF1481C Fence Painting

Node-v download and application, ES6 module import and export

数据库操作 题目一

高数 | 武爷『经典系列』每日一题思路及易错点总结

对标注文件夹进行清洗

Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world

220. Presence of repeating element III

jvm命令归纳

187. Repeated DNA sequence

Media at home and abroad publicize that we should strictly grasp the content
随机推荐
Set of pl/sql
(2006,Mysql Server has gone away)问题处理
Pat grade a a1076 forwards on Weibo
Study notes of automatic control principle -- correction and synthesis of automatic control system
Innovus卡住,提示X Error:
QtCreator报错:You need to set an executable in the custom run configuration.
at、crontab
Day06 homework - skill question 6
Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
ES6 modular import and export) (realize page nesting)
《Datawhale熊猫书》出版了!
Nuxt - 项目打包部署及上线到服务器流程(SSR 服务端渲染)
day06 作业--技能题2
838. 堆排序
187. Repeated DNA sequence
Day06 homework -- skill question 2
Day 6 summary & database operation
Numpy Foundation
Day06 operation -- addition, deletion, modification and query
基于序的评价指标 (特别针对推荐系统和多标签学习)