当前位置:网站首页>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 
边栏推荐
- 百度评论中台的设计与探索
- [Yugong series] go teaching course 003-ide installation and basic use in July 2022
- Design and exploration of Baidu comment Center
- 【el-table如何禁用】
- Apache dolphin scheduler system architecture design
- 22-07-04 Xi'an Shanghao housing project experience summary (01)
- Unity skframework framework (24), avatar controller third person control
- 7 月 2 日邀你来TD Hero 线上发布会
- Wechat applet obtains household area information
- Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图
猜你喜欢

Principle and performance analysis of lepton lossless compression

Officially launched! Tdengine plug-in enters the official website of grafana

H. 265 introduction to coding principles

Analysis on the wallet system architecture of Baidu trading platform

Community group buying exploded overnight. How should this new model of e-commerce operate?

How to choose the right chain management software?

Lepton 无损压缩原理及性能分析

What are the advantages of the live teaching system to improve learning quickly?

【数组的中的某个属性的监听】

The popularity of B2B2C continues to rise. What are the benefits of enterprises doing multi-user mall system?
随机推荐
[hungry dynamic table]
使用el-upload封装得组件怎么清空已上传附件
Go 语言使用 MySQL 的常见故障分析和应对方法
Tutorial on building a framework for middle office business system
Getting started with Apache dolphin scheduler (one article is enough)
Lepton 无损压缩原理及性能分析
Fluent development: setting method of left and right alignment of child controls in row
Tdengine offline upgrade process
解决Navicat激活、注册时候出现No All Pattern Found的问题
How Windows bat script automatically executes sqlcipher command
Project practice | excel export function
LeetCode 556. Next bigger element III
TDengine 离线升级流程
TDengine 连接器上线 Google Data Studio 应用商店
Principle and performance analysis of lepton lossless compression
让AI替企业做复杂决策真的靠谱吗?参与直播,斯坦福博士来分享他的选择|量子位·视点...
Unity SKFramework框架(二十三)、MiniMap 小地图工具
[JS sort according to the attributes in the object array]
From "chemist" to developer, from Oracle to tdengine, two important choices in my life
Deep understanding of C language pointer