当前位置:网站首页>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
边栏推荐
- Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
- 剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
- Node の MongoDB Driver
- Tongweb set gzip
- The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
- 基于宽表的数据建模应用
- Getting started with Apache dolphin scheduler (one article is enough)
- Kotlin Compose 与原生 嵌套使用
- LeetCode 556. Next bigger element III
- 【对象数组a与对象数组b取出id不同元素赋值给新的数组】
猜你喜欢
Node の MongoDB Driver
Apache DolphinScheduler 系统架构设计
Apache dolphin scheduler system architecture design
Community group buying has triggered heated discussion. How does this model work?
百度评论中台的设计与探索
TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
cent7安装Oracle数据库报错
从“化学家”到开发者,从甲骨文到 TDengine,我人生的两次重要抉择
Tongweb set gzip
Why do offline stores need cashier software?
随机推荐
植物大战僵尸Scratch
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
uni-app---uni. Navigateto jump parameter use
Lepton 无损压缩原理及性能分析
Online chain offline integrated chain store e-commerce solution
Community group buying exploded overnight. How should this new model of e-commerce operate?
Unity SKFramework框架(二十四)、Avatar Controller 第三人称控制
Solve the problem of no all pattern found during Navicat activation and registration
About getfragmentmanager () and getchildfragmentmanager ()
Tdengine already supports the industrial Intel edge insight package
基于模板配置的数据可视化平台
Kotlin Compose 与原生 嵌套使用
Unity SKFramework框架(二十三)、MiniMap 小地图工具
Analysis on the wallet system architecture of Baidu trading platform
H.265编码原理入门
Gradientdrawable get a single color
[listening for an attribute in the array]
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
How Windows bat script automatically executes sqlcipher command