当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
PAT 甲级 A1076 Forwards on Weibo
原根与NTT 五千字详解
JS file import of node
The child and binary tree- open root inversion of polynomials
Review notes of Microcomputer Principles -- zoufengxing
JS closure: binding of functions to their lexical environment
at、crontab
Flask project learning (I) -- sayhello
Babbitt | metauniverse daily must read: does the future of metauniverse belong to large technology companies or to the decentralized Web3 world
Simple message mechanism of unity
ext3文件系统的一个目录下,无法创建子文件夹,但可以创建文件
CF1481C Fence Painting
PAT 甲级 A1034 Head of a Gang
Pop up window in Win 11 opens with a new tab ---firefox
基于序的评价指标 (特别针对推荐系统和多标签学习)
[leetcode database 1050] actors and directors who have cooperated at least three times (simple question)
围棋智能机器人阿法狗,阿尔法狗机器人围棋
Database operation topic 1
NFT与数字藏品到底有何区别?
2022流动式起重机司机考试题模拟考试题库模拟考试平台操作