当前位置:网站首页>Currently clicked button and current mouse coordinates in QT judgment interface

Currently clicked button and current mouse coordinates in QT judgment interface

2022-07-05 06:11:00 my_ angle2016

1.QObject::sender( ) Returns the pointer of the object that sent the signal , The return type is QObject* . You can use qobject_cast The dynamic type is converted into the corresponding object of sending information ( The base class of the object class needs to have QObject).

QObject::objectName( ) Returns the name of the object (QString)

QPushButton*btn = qobject_cast<QPushButton*>(sender());// Get the object that transmits the signal 
 if(" Button object name "==btn->objectName()){// If you get an object 
 //...
 }

2. QMouseEvent Two kinds of coordinate systems , One is window coordinates ( Relative coordinates ), One is the display coordinates ( Global coordinates )

QPointQMouseEvent::globalPos();// Window coordinates , This is to return the global coordinates of the mouse 
 QPointQCursor::pos()[static];// Returns the global coordinates relative to the display 
 QPointQMouseEvent::pos();// Return relative to this widget The location of 
 QPointQWidget::pos();// This property gets the current position of the control in the parent window 
 constQPointF&QMouseEvent::screenPos()const;// and QPoint QMouseEvent::globalPos()  Same value , But the type is more precise QPointF
 QPointQWidget::mapToGlobal(constQPoint& pos)const;// Convert window coordinates into display coordinates 
 QPointQWidget::mapFromGlobal(constQPoint& pos)const;// Convert the display coordinates into window coordinates 
 QPointQWidget::mapToParent(constQPoint& pos)const;// Get the window coordinates pos Convert to parent class widget Coordinates of 
 QPointQWidget::mapFromParent(constQPoint& pos)const;// Convert the parent window coordinates to the current window coordinates 
 QPointQWidget::mapTo(constQWidget* parent,constQPoint& pos)const;// Convert the current window coordinates to the specified parent coordinate 
 // You can also use :
 Qpoint pt=cursor().pos();// Get the current mouse position 

原网站

版权声明
本文为[my_ angle2016]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/186/202207050543214012.html