当前位置:网站首页>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
边栏推荐
- 【OpenCV 例程200篇】219. 添加数字水印(盲水印)
- Kotlin Compose 多个条目滚动
- Why do offline stores need cashier software?
- 写入速度提升数十倍,TDengine 在拓斯达智能工厂解决方案上的应用
- LeetCode 31. Next spread
- Theme. AppCompat. Light. Darkactionbar not found
- On July 2, I invite you to TD Hero online press conference
- [sorting of object array]
- Roll up, break 35 - year - old Anxiety, animation Demonstration CPU recording Function call Process
- 90%的人都不懂的泛型,泛型的缺陷和应用场景
猜你喜欢
Oracle combines multiple rows of data into one row of data
百度评论中台的设计与探索
90%的人都不懂的泛型,泛型的缺陷和应用场景
Community group buying has triggered heated discussion. How does this model work?
Apache dolphin scheduler system architecture design
LeetCode 31. Next spread
[listening for an attribute in the array]
Lepton 无损压缩原理及性能分析
Unity SKFramework框架(二十三)、MiniMap 小地图工具
How to choose the right chain management software?
随机推荐
Data visualization platform based on template configuration
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
A keepalived high availability accident made me learn it again
Apache dolphin scheduler system architecture design
MYSQL 对字符串类型排序不生效问题
解决Navicat激活、注册时候出现No All Pattern Found的问题
TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
SQL learning - case when then else
90%的人都不懂的泛型,泛型的缺陷和应用场景
Gradientdrawable get a single color
[sourcetree configure SSH and use]
Unity skframework framework (24), avatar controller third person control
植物大战僵尸Scratch
百度评论中台的设计与探索
The most comprehensive promotion strategy: online and offline promotion methods of E-commerce mall
Kotlin Compose 多个条目滚动
Develop and implement movie recommendation applet based on wechat cloud
Flutter development: use safearea
[object array A and object array B take out different elements of ID and assign them to the new array]
uni-app---uni. Navigateto jump parameter use