当前位置:网站首页>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
边栏推荐
- Understand the window query function of tdengine in one article
- Principle and performance analysis of lepton lossless compression
- Fluent development: setting method of left and right alignment of child controls in row
- Resolve the horizontal (vertical) sliding conflict between viewpager and WebView
- 百度评论中台的设计与探索
- tongweb设置gzip
- 小程序启动性能优化实践
- Viewpager pageradapter notifydatasetchanged invalid problem
- Apache DolphinScheduler 系统架构设计
- What are the advantages of the live teaching system to improve learning quickly?
猜你喜欢
Unity skframework framework (24), avatar controller third person control
【技术直播】如何用 VSCode 从 0 到 1 改写 TDengine 代码
Officially launched! Tdengine plug-in enters the official website of grafana
How to correctly evaluate video image quality
Go 语言使用 MySQL 的常见故障分析和应对方法
H.265编码原理入门
oracle 多行数据合并成一行数据
H. 265 introduction to coding principles
【sourceTree配置SSH及使用】
TDengine 已经支持工业英特尔 边缘洞见软件包
随机推荐
How to choose the right chain management software?
7 月 2 日邀你来TD Hero 线上发布会
What should we pay attention to when entering the community e-commerce business?
SQL learning alter add new field
Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
[sourcetree configure SSH and use]
22-07-04 Xi'an Shanghao housing project experience summary (01)
How do enterprises choose the appropriate three-level distribution system?
Roll up, break through 35 year old anxiety, and animate the CPU to record the function call process
Why does everyone want to do e-commerce? How much do you know about the advantages of online shopping malls?
Application of data modeling based on wide table
【C语言】动态内存开辟的使用『malloc』
Are databases more popular as they get older?
Three-level distribution is becoming more and more popular. How should businesses choose the appropriate three-level distribution system?
Deep understanding of C language pointer
Tdengine already supports the industrial Intel edge insight package
【两个对象合并成一个对象】
Principle and performance analysis of lepton lossless compression
Observation cloud and tdengine have reached in-depth cooperation to optimize the cloud experience of enterprises
Flutter development: a way to solve the problem of blank space on the top of listview