Qt获取控件位置坐标详解

1.     QPoint QMouseEvent::pos()

     这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。

      const Returns the position of the mouse cursor, relative to the widgetthat received the event. If you move the widget as a result of the mouse event,use the global position returned by globalPos() to avoid a shaking motion.

2.     QPoint QMouseEvent::globalPos()

     窗口坐标,这个是返回鼠标的全局坐标

    const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like X11. Whenever youmove your widgets around in response to mouse events, globalPos() may differ alot from the current pointer position QCursor::pos(), and fromQWidget::mapToGlobal(pos()).

3.     QPoint QCursor::pos() [static]

     返回相对显示器的全局坐标

     Returns the position of the cursor (hot spot) of the primary screen inglobal screen coordinates. You can call QWidget::mapFromGlobal() to translateit to widget coordina

你可能感兴趣的:(Qt开发实战宝典,qt)