当前位置:网站首页>QT how to detect whether the mouse is on a control
QT how to detect whether the mouse is on a control
2022-07-04 14:09:00 【Licht powder】
Mode one : recommend , I feel that this event filter method is sensitive
Remember to install the event filter
this->installEventFilter(this);
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
// Events to be filtered
if (event->type() == QEvent::MouseMove)
{
QMouseEvent* mouseEvent = (QMouseEvent*)event;
QPoint p = mouseEvent->pos();
int x = m_LightAddrAndDmxList.value(m_iCurrentTablevie)->x();
int y = m_LightAddrAndDmxList.value(m_iCurrentTablevie)->y();
int w =m_LightAddrAndDmxList.value(m_iCurrentTablevie)->w();
int h = m_LightAddrAndDmxList.value(m_iCurrentTablevie)->h();
if(( x<p.x() && p.x()<w) && ( y<p.y() && p.y()<h))// The coordinates of the control relative to the application
{
return true;
}
// Do what you want here
return true;
}
return QWidget::eventFilter(obj,event);
The above function can also have a layer , Select the corresponding control you want to install this event filter
such as :
// Events to be filtered
if(obj == ui->lineEdit)// The object of monitoring
{
if (event->type() == QEvent::MouseMove)
{
……
return true;
}
}
return QWidget::eventFilter(obj,event);
Mode two : Rewrite mouse events
void mouseMoveEvent(QMouseEvent *ev);
If the control has a father , Remember to also set up mouse tracking
// Set the default tracking mouse , Otherwise, when the mouse movement is triggered , You must click it first to be effective
this->setMouseTracking(true);
void MyLabel::mouseMoveEvent(QMouseEvent *ev)
{
// Mouse position
int i=ev->x();
int j=ev->y();
}
The above two methods can dynamically monitor whether the mouse is on a control
Mode three : static state
if(!ui->lineEdit->geometry().contains(this->mapFromGlobal(QCursor::pos())));
Mode 4 : static state :
if(ui->lineEdit->underMouse)
边栏推荐
- find命令报错: paths must precede expression(转)
- . Net delay queue
- Animation and transition effects
- Understanding and difference between viewbinding and databinding
- 德明利深交所上市:市值31亿 为李虎与田华夫妻档
- 忠诚协议是否具有法律效力
- 【Antd踩坑】Antd Form 配合Input.Group时出现Form.Item所占据的高度不对
- Source code compilation and installation of MySQL
- MySQL version 8 installation Free Tutorial
- go vendor 项目迁移到 mod 项目
猜你喜欢
Openharmony application development how to create dayu200 previewer
392. 判断子序列
Haproxy high availability solution
Automatic filling of database public fields
Interviewer: what is the internal implementation of hash data type in redis?
面试官:Redis中哈希数据类型的内部实现方式是什么?
2022g3 boiler water treatment examination question simulation examination question bank and simulation examination
. Net delay queue
吃透Chisel语言.11.Chisel项目构建、运行和测试(三)——Chisel测试之ScalaTest
[R language data science]: cross validation and looking back
随机推荐
Huahao Zhongtian sprint Technology Innovation Board: perte annuelle de 280 millions de RMB, projet de collecte de fonds de 1,5 milliard de Beida Pharmaceutical est actionnaire
Install MySQL
好博医疗冲刺科创板:年营收2.6亿 万永钢和沈智群为实控人
Getting started with microservices
Byte interview algorithm question
C language programming topic reference
程序员的焦虑
以房抵债能否排除强制执行
安装Mysql
markdown 语法之字体标红
30: Chapter 3: develop Passport Service: 13: develop [change / improve user information, interface]; (use * * * Bo class to accept parameters, and use parameter verification)
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
C language staff management system
舔狗舔到最后一无所有(状态机)
Source code compilation and installation of MySQL
MySQL45讲——学习极客时间MySQL实战45讲笔记—— 06 | 全局锁和表锁_给表加个字段怎么有这么多阻碍
ASP. Net core introduction I
吃透Chisel语言.06.Chisel基础(三)——寄存器和计数器
MySQL 5 installation and modification free
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)