当前位置:网站首页>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 插件入驻 Grafana 官网
- Tutorial on building a framework for middle office business system
- 盗版DALL·E成梗图之王?日产5万张图像,挤爆抱抱脸服务器,OpenAI勒令改名
- uni-app---uni. Navigateto jump parameter use
- Apache DolphinScheduler 系统架构设计
- [team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
- First understanding of structure
- What about wechat mall? 5 tips to clear your mind
- From "chemist" to developer, from Oracle to tdengine, two important choices in my life
- Online chain offline integrated chain store e-commerce solution
猜你喜欢
Kotlin Compose 与原生 嵌套使用
移动端异构运算技术-GPU OpenCL编程(进阶篇)
Online chain offline integrated chain store e-commerce solution
Lepton 无损压缩原理及性能分析
Why do offline stores need cashier software?
[listening for an attribute in the array]
基于模板配置的数据可视化平台
观测云与 TDengine 达成深度合作,优化企业上云体验
mysql安装配置以及创建数据库和表
使用el-upload封装得组件怎么清空已上传附件
随机推荐
Understand the window query function of tdengine in one article
Tutorial on building a framework for middle office business system
Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
Unity skframework framework (XXIII), minimap small map tool
Community group buying has triggered heated discussion. How does this model work?
LeetCode 496. Next larger element I
分布式数据库下子查询和 Join 等复杂 SQL 如何实现?
7 月 2 日邀你来TD Hero 线上发布会
Gradientdrawable get a single color
Lepton 无损压缩原理及性能分析
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
Three-level distribution is becoming more and more popular. How should businesses choose the appropriate three-level distribution system?
【对象数组的排序】
[JS sort according to the attributes in the object array]
How to correctly evaluate video image quality
一文读懂TDengine的窗口查询功能
写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
初识结构体
Understanding of smt32h7 series DMA and DMAMUX
A keepalived high availability accident made me learn it again