Qt 获取控件位置坐标,屏幕坐标,相对父窗体坐标
QPoint QMouseEvent::pos()
这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。
QPoint QMouseEvent::globalPos()
窗口坐标,这个是返回鼠标的全局坐标
QPoint QCursor::pos() [static]
返回鼠标相对显示器的全局坐标
QPoint QWidget::mapToGlobal(const QPoint & pos) const
将窗口坐标转换成显示器坐标
QPoint QWidget::mapFromGlobal(const QPoint & pos) const
将显示器坐标转换成窗口坐标
QPoint QWidget::mapToParent(const QPoint & pos) const
将窗口坐标获得的pos转换成父类widget的坐标
QPoint QWidget::mapFromParent(const QPoint & pos) const
将父类窗口坐标转换成当前窗口坐标
QPoint QWidget::mapTo(const QWidget * parent, const QPoint &pos) const
将当前窗口坐标转换成指定parent坐标。
QWidget::pos() : QPoint
这个属性获得的是当前目前控件在父窗口中的位置,
const QPointF &QMouseEvent::screenPos() const
Returns the position of the mouse cursor asa QPointF, relative to the screen that received the event.
和QPoint QMouseEvent::globalPos() 值相同,但是类型更高精度的QPointF
This function was introduced in Qt 5.0.
QCursor::pos() == QMouseEvent::globalPos()
获取全局坐标
QMouseEvent::globalPos() == ui.posBtn->mapToGlobal(ui.posBtn->pos());
将鼠标的坐标转换成全局坐标。
ui.posBtn->mapFromGlobal(QCursor::pos());
将全局坐标(鼠标当前坐标,QCursor::pos())直接转换成当前窗口相对坐标