当前位置:网站首页>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
边栏推荐
- TDengine 已经支持工业英特尔 边缘洞见软件包
- How to correctly evaluate video image quality
- 让AI替企业做复杂决策真的靠谱吗?参与直播,斯坦福博士来分享他的选择|量子位·视点...
- [app packaging error] to proceed, either fix the issues identified by lint, or modify your build script as follow
- 盗版DALL·E成梗图之王?日产5万张图像,挤爆抱抱脸服务器,OpenAI勒令改名
- Data visualization platform based on template configuration
- Oracle combines multiple rows of data into one row of data
- TDengine 离线升级流程
- LeetCode 496. Next larger element I
- 植物大战僵尸Scratch
猜你喜欢
为什么不建议你用 MongoDB 这类产品替代时序数据库?
[sourcetree configure SSH and use]
Design and exploration of Baidu comment Center
Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图
Apache dolphin scheduler system architecture design
小程序启动性能优化实践
Windows uses commands to run kotlin
代码语言的魅力
【数组的中的某个属性的监听】
Dry goods sorting! How about the development trend of ERP in the manufacturing industry? It's enough to read this article
随机推荐
单片机原理与接口技术(ESP8266/ESP32)机器人类草稿
【OpenCV 例程200篇】219. 添加数字水印(盲水印)
盗版DALL·E成梗图之王?日产5万张图像,挤爆抱抱脸服务器,OpenAI勒令改名
Lepton 无损压缩原理及性能分析
写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
Understanding of smt32h7 series DMA and DMAMUX
百度APP 基于Pipeline as Code的持续集成实践
LeetCode 503. Next bigger Element II
解决idea调试过程中liquibase – Waiting for changelog lock….导致数据库死锁问题
Evolution of Baidu intelligent applet patrol scheduling scheme
Data visualization platform based on template configuration
Charm of code language
【js 根据对象数组中的属性进行排序】
使用el-upload封装得组件怎么清空已上传附件
How Windows bat script automatically executes sqlcipher command
【对象数组的排序】
百度智能小程序巡检调度方案演进之路
卷起来,突破35岁焦虑,动画演示CPU记录函数调用过程
Common fault analysis and Countermeasures of using MySQL in go language
Unity SKFramework框架(二十二)、Runtime Console 运行时调试工具