当前位置:网站首页>QT判断界面当前点击的按钮和当前鼠标坐标
QT判断界面当前点击的按钮和当前鼠标坐标
2022-07-05 05:43:00 【my_angle2016】
1.QObject::sender( ) 返回发送信号的对象的指针,返回类型为QObject* 。可使用qobject_cast动态类型转换成对应的发送信息的对象(对象类的基类中需要有QObject)。
QObject::objectName( ) 返回对象的名称(QString)
QPushButton*btn = qobject_cast<QPushButton*>(sender());//获取发射信号的对象
if("按钮对象名"==btn->objectName()){//如果获取到对象
//...
}
2. QMouseEvent中两类坐标系统,一类是窗口坐标(相对坐标),一类是显示器坐标(全局坐标)
QPointQMouseEvent::globalPos();//窗口坐标,这个是返回鼠标的全局坐标
QPointQCursor::pos()[static];//返回相对显示器的全局坐标
QPointQMouseEvent::pos();//返回相对这个widget的位置
QPointQWidget::pos();//这个属性获得的是当前目前控件在父窗口中的位置
constQPointF&QMouseEvent::screenPos()const;//和QPoint QMouseEvent::globalPos() 值相同,但是类型更高精度的QPointF
QPointQWidget::mapToGlobal(constQPoint& pos)const;//将窗口坐标转换成显示器坐标
QPointQWidget::mapFromGlobal(constQPoint& pos)const;//将显示器坐标转换成窗口坐标
QPointQWidget::mapToParent(constQPoint& pos)const;//将窗口坐标获得的pos转换成父类widget的坐标
QPointQWidget::mapFromParent(constQPoint& pos)const;//将父类窗口坐标转换成当前窗口坐标
QPointQWidget::mapTo(constQWidget* parent,constQPoint& pos)const;//将当前窗口坐标转换成指定parent坐标
//也可使用:
Qpoint pt=cursor().pos();//获取当前鼠标位置
边栏推荐
- CCPC Weihai 2021m eight hundred and ten thousand nine hundred and seventy-five
- How to adjust bugs in general projects ----- take you through the whole process by hand
- Individual game 12
- Drawing dynamic 3D circle with pure C language
- Common optimization methods
- Add level control and logger level control of Solon logging plug-in
- 中职网络安全技能竞赛——广西区赛中间件渗透测试教程文章
- Dynamic planning solution ideas and summary (30000 words)
- kubeadm系列-00-overview
- SSH password free login settings and use scripts to SSH login and execute instructions
猜你喜欢
剑指 Offer 53 - II. 0~n-1中缺失的数字
CF1637E Best Pair
Brief introduction to tcp/ip protocol stack
[jailhouse article] look mum, no VM exits
Introduction et expérience de wazuh open source host Security Solution
sync. Interpretation of mutex source code
剑指 Offer 35.复杂链表的复制
读者写者模型
Dynamic planning solution ideas and summary (30000 words)
Light a light with stm32
随机推荐
Pointnet++ learning
6. Logistic model
PC寄存器
Csp-j-2020-excellent split multiple solutions
剑指 Offer 53 - I. 在排序数组中查找数字 I
Haut OJ 1401: praise energy
Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
软件测试 -- 0 序
Simple knapsack, queue and stack with deque
Sword finger offer 05 Replace spaces
Support multi-mode polymorphic gbase 8C database continuous innovation and heavy upgrade
Talking about JVM (frequent interview)
Summary of Haut OJ 2021 freshman week
Add level control and logger level control of Solon logging plug-in
Reflection summary of Haut OJ freshmen on Wednesday
Introduction to convolutional neural network
Zzulioj 1673: b: clever characters???
Remote upgrade afraid of cutting beard? Explain FOTA safety upgrade in detail
Sword finger offer 35 Replication of complex linked list
全国中职网络安全B模块之国赛题远程代码执行渗透测试 //PHPstudy的后门漏洞分析