当前位置:网站首页>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)
边栏推荐
- 【Matlab】conv、filter、conv2、filter2和imfilter卷积函数总结
- 程序员的焦虑
- Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
- Getting started with the go language is simple: go implements the Caesar password
- MySQL version 8 installation Free Tutorial
- Go 语言入门很简单:Go 实现凯撒密码
- One of the solutions for unity not recognizing riders
- Service Mesh的基本模式
- Applet live + e-commerce, if you want to be a new retail e-commerce, use it!
- Apple 5g chip research and development failure: continue to rely on Qualcomm, but also worry about being prosecuted?
猜你喜欢
【FAQ】华为帐号服务报错 907135701的常见原因总结和解决方法
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
JVM memory layout detailed, illustrated, well written!
Getting started with the go language is simple: go implements the Caesar password
[R language data science]: cross validation and looking back
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
自主工业软件的创新与发展
205. 同构字符串
随机推荐
markdown 语法之字体标红
Introduction to reverse debugging PE structure resource table 07/07
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
Summary of recent days (non-technical article)
Fs4056 800mA charging IC domestic fast charging power IC
2022 hoisting machinery command examination simulation 100 questions simulation examination platform operation
Read excel table data
Huahao Zhongtian rushes to the scientific and Technological Innovation Board: the annual loss is 280million, and it is proposed to raise 1.5 billion. Beida pharmaceutical is a shareholder
Dgraph: large scale dynamic graph dataset
程序员的焦虑
qt 怎么检测鼠标在不在某个控件上
奇妙秘境 码蹄集
IDEA快捷键大全
MongoDB常用28条查询语句(转)
Getting started with microservices
華昊中天沖刺科創板:年虧2.8億擬募資15億 貝達藥業是股東
Variable promotion and function promotion in JS
go vendor 项目迁移到 mod 项目
js中的变量提升和函数提升