当前位置:网站首页>QT | about how to use EventFilter
QT | about how to use EventFilter
2022-07-26 09:11:00 【InfoQ】
Preface :
Usage method :
- 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);
}
}
Why use filters :
Send events :
- bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event);
- void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
sendEvent and postEvent The difference between :
- sendEvent() The given event will be processed immediately ; and postEvent() The event will be placed in the waiting queue , Next time Qt Only when the main event loop is running will it be processed .
- sendEvent() Medium QEvent The formation parameters cannot be automatically deleted after the event is sent , So you need to create on the stack QEvent object ; and postEvent() Medium QEvent Object parameters must be created on the heap ( For example, using new), When an event is sent, the event queue will automatically delete it .
QKeyEvent myEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModify);
qApp->sendEvent(ui->spinBox, &myEvent);// Send keyboard events to spinbox parts
边栏推荐
- 对象型的集合按某个属性的值进行去重
- tornado之多进程服务
- Self review ideas of probability theory
- 服务器内存故障预测居然可以这样做!
- The essence of attack and defense strategy behind the noun of network security
- 李沐d2l(六)---模型选择
- 公告 | FISCO BCOS v3.0-rc4发布,新增Max版,可支撑海量交易上链
- NTT(快速数论变换)多项式求逆 一千五百字解析
- Overview of motion recognition evaluation
- CF1481C Fence Painting
猜你喜欢
![[leetcode database 1050] actors and directors who have cooperated at least three times (simple question)](/img/ab/bad6b86039384af7b829bef5316923.png)
[leetcode database 1050] actors and directors who have cooperated at least three times (simple question)

Elastic APM安装和使用

Two tips for pycharm to open multiple projects

C# Serialport的发送和接收

The idea shortcut key ALT realizes the whole column operation

NTT (fast number theory transformation) polynomial inverse 1500 word analysis

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

服务器内存故障预测居然可以这样做!

Unity topdown character movement control

Day06 homework -- skill question 2
随机推荐
聪明的美食家 C语言
对标注文件夹进行清洗
day06 作业--技能题1
Database operation topic 2
Learning notes of automatic control principle - Performance Analysis of continuous time system
ES6 modular import and export) (realize page nesting)
围棋智能机器人阿法狗,阿尔法狗机器人围棋
MySQL 强化知识点
Introduction to excellent verilog/fpga open source project (30) - brute force MD5
Web overview and b/s architecture
李沐d2l(四)---Softmax回归
“No input file specified “问题的处理
Canal 的学习笔记
Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
论文笔记: 知识图谱 KGAT (未完暂存)
优秀的 Verilog/FPGA开源项目介绍(三十零)- 暴力破解MD5
分布式跟踪系统选型与实践
[eslint] Failed to load parser ‘@typescript-eslint/parser‘ declared in ‘package. json » eslint-confi
垂直搜索
Grain College of all learning source code