当前位置:网站首页>QT event filter simple case
QT event filter simple case
2022-07-05 09:55:00 【Sunqk5665】
Catalog
1、 Create a new one widget,ui The interface design is as follows

2、widget.h Add constructor to

bool eventFilter(QObject *watched, QEvent *event);
3、 stay widget.cpp Add the following code to
Add header file 
#include <QKeyEvent>
#include <QWheelEvent>
Install the filter :
ui->textEdit->installEventFilter(this);
ui->spinBox->installEventFilter(this);
ui->label->installEventFilter(this);
Add filter refactoring function :
bool Widget::eventFilter(QObject *watched, QEvent *event)
{
if(watched==ui->textEdit)
{
if(event->type()==QEvent::Wheel)
{
QWheelEvent *wheelEvent = (QWheelEvent*)event;
if(wheelEvent->delta()>0)
ui->textEdit->zoomIn();
else
ui->textEdit->zoomOut();
}
}
else if(watched==ui->spinBox)
{
if(event->type()==QEvent::KeyPress)
{
QKeyEvent *keyEvent = (QKeyEvent*)event;
if(keyEvent->key()==Qt::Key_Space)
ui->spinBox->setValue(0);
}
}
else if(watched==ui->label)
{
if(event->type()==QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = (QMouseEvent*)event;
if(mouseEvent->button()==Qt::LeftButton)
ui->textEdit->setText(tr(" Left click on the picture !"));
else if(mouseEvent->button()==Qt::RightButton)
ui->textEdit->setText(tr(" Right click on the picture !"));
}
}
else
return QWidget::eventFilter(watched,event);
return false;
}
4、 Run the project
Click the picture with the left mouse button 
Right click on the picture 
Mouse in textEdit Slide the roller up , Changed the font size 
边栏推荐
- mysql80服务不启动
- 使用el-upload封装得组件怎么清空已上传附件
- 为什么不建议你用 MongoDB 这类产品替代时序数据库?
- Resolve the horizontal (vertical) sliding conflict between viewpager and WebView
- Getting started with Apache dolphin scheduler (one article is enough)
- [how to disable El table]
- 22-07-04 Xi'an Shanghao housing project experience summary (01)
- Charm of code language
- SQL learning - case when then else
- TDengine可通过数据同步工具 DataX读写
猜你喜欢

From "chemist" to developer, from Oracle to tdengine, two important choices in my life

Cross process communication Aidl

【技术直播】如何用 VSCode 从 0 到 1 改写 TDengine 代码

Kotlin Compose 多个条目滚动

Observation cloud and tdengine have reached in-depth cooperation to optimize the cloud experience of enterprises

如何正确的评测视频画质

为什么不建议你用 MongoDB 这类产品替代时序数据库?

oracle 多行数据合并成一行数据

Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图

百度评论中台的设计与探索
随机推荐
Node の MongoDB Driver
How do enterprises choose the appropriate three-level distribution system?
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
[two objects merged into one object]
MySQL does not take effect in sorting string types
如何正确的评测视频画质
What should we pay attention to when developing B2C websites?
E-commerce apps are becoming more and more popular. What are the advantages of being an app?
How to improve the operation efficiency of intra city distribution
Cross process communication Aidl
Project practice | excel export function
Tutorial on building a framework for middle office business system
Unity skframework framework (XXII), runtime console runtime debugging tool
Flutter development: a way to solve the problem of blank space on the top of listview
TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
【OpenCV 例程200篇】219. 添加数字水印(盲水印)
从“化学家”到开发者,从甲骨文到 TDengine,我人生的两次重要抉择
解决idea调试过程中liquibase – Waiting for changelog lock….导致数据库死锁问题
Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
让AI替企业做复杂决策真的靠谱吗?参与直播,斯坦福博士来分享他的选择|量子位·视点...