当前位置:网站首页>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)
边栏推荐
- 忠诚协议是否具有法律效力
- 常见 content-type对应表
- 美国土安全部长:国内暴力极端主义是目前美面临的最大恐怖主义威胁之一
- 逆向调试入门-PE结构-资源表07/07
- 舔狗舔到最后一无所有(状态机)
- 源码编译安装MySQL
- 基于PaddleX的智能零售柜商品识别
- 中邮科技冲刺科创板:年营收20.58亿 邮政集团是大股东
- Understanding and difference between viewbinding and databinding
- Yingshi Ruida rushes to the scientific and Technological Innovation Board: the annual revenue is 450million and the proposed fund-raising is 979million
猜你喜欢
SCM polling program framework based on linked list management
MySQL version 8 installation Free Tutorial
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
205. 同构字符串
2022年起重机械指挥考试模拟100题模拟考试平台操作
吃透Chisel语言.10.Chisel项目构建、运行和测试(二)——Chisel中生成Verilog代码&Chisel开发流程
[R language data science]: cross validation and looking back
近日小结(非技术文)
2022kdd pre lecture | 11 first-class scholars take you to unlock excellent papers in advance
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
随机推荐
结合案例:Flink框架中的最底层API(ProcessFunction)用法
DGraph: 大规模动态图数据集
One of the solutions for unity not recognizing riders
吃透Chisel语言.04.Chisel基础(一)——信号类型和常量
FS7867S是一款应用于数字系统供电电源电压监控的电压检测芯片
常见 content-type对应表
【R语言数据科学】:交叉验证再回首
Can mortgage with housing exclude compulsory execution
golang fmt.printf()(转)
英视睿达冲刺科创板:年营收4.5亿 拟募资9.79亿
Doctoral application | West Lake University Learning and reasoning system laboratory recruits postdoctoral / doctoral / research internship, etc
WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
吃透Chisel语言.07.Chisel基础(四)——Bundle和Vec
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
[C question set] of VII
1200. 最小绝对差
MongoDB常用28条查询语句(转)
CVPR 2022 | 大幅减少零样本学习所需的人工标注,提出富含视觉信息的类别语义嵌入(源代码下载)...
Understanding and difference between viewbinding and databinding
Install Trinity and solve error reporting