qt globalPos localPos   screenPos windowPos pos

本文章摘抄自多個博主文章,未經過驗證

摘抄文章1(qt官方在線文檔):

https://doc.qt.io/qt-5/qmouseevent.html

QPoint QMouseEvent::globalPos() const

Returns the global position of the mouse cursor at the time of the event. This is important on asynchronous window systems like X11. Whenever you move your widgets around in response to mouse events, globalPos() may differ a lot from the current pointer position QCursor::pos(), and from QWidget::mapToGlobal(pos()).

See also globalX() and globalY().

int QMouseEvent::globalX() const

Returns the global x position of the mouse cursor at the time of the event.

See also globalY() and globalPos().

int QMouseEvent::globalY() const

Returns the global y position of the mouse cursor at the time of the event.

See also globalX() and globalPos().

const QPointF &QMouseEvent::localPos() const

Returns the position of the mouse cursor as a QPointF, relative to the widget or item that received the event.

If you move the widget as a result of the mouse event, use the screen position returned by screenPos() to avoid a shaking motion.

This function was introduced in Qt 5.0.

See also x(), y(), windowPos(), and screenPos().

QPoint QMouseEvent::pos() const

Returns the position of the mouse cursor, relative to the widget that 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.

See also x(), y(), and globalPos().

const QPointF &QMouseEvent::screenPos() const

Returns the position of the mouse cursor as a QPointF, relative to the screen that received the event.

This function was introduced in Qt 5.0.

See also x(), y(), pos(), localPos(), and windowPos().

Qt::MouseEventSource QMouseEvent::source() const

Returns information about the mouse event source.

The mouse event source can be used to distinguish between genuine and artificial mouse events. The latter are events that are synthesized from touch events by the operating system or Qt itself.

Note: Many platforms provide no such information. On such platforms Qt::MouseEventNotSynthesized is returned always.

This function was introduced in Qt 5.3.

See also Qt::MouseEventSource and QGraphicsSceneMouseEvent::source().

const QPointF &QMouseEvent::windowPos() const

Returns the position of the mouse cursor as a QPointF, relative to the window that 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.

This function was introduced in Qt 5.0.

See also x(), y(), pos(), localPos(), and screenPos().

int QMouseEvent::x() const

Returns the x position of the mouse cursor, relative to the widget that received the event.

See also y() and pos().

int QMouseEvent::y() const

Returns the y position of the mouse cursor, relative to the widget that received the event.

See also x() and pos().

 

摘抄文章2:https://www.it610.com/article/5322077.htm

globalPos()

int globalX() const
int globalY() const

返回鼠標的全局位置

屏幕左上角爲0 0

localPos() 

x()

y()

相對於接受消息窗口的位置

screenPos()

和globalPos一樣。一個是Int 一個是float

windowPos

和local一樣。一個是Int 一個是float

 

摘抄文章3:https://blog.csdn.net/u013394556/article/details/38797295

globalPos(),給出的座標信息是相對於桌面的,即以桌面左上角爲原點。

pos(),是相對於窗口的,以窗口左上角爲原點(去除邊框)。即pos()給出的是一個相對位置座標。而globalPos(),給出的是一個絕對座標。

 

摘抄文章4:https://blog.csdn.net/imxiangzi/article/details/50742845

FROM:  http://blog.163.com/qimo601@126/blog/static/158220932014423114030117/

1、QPoint QMouseEvent::pos() 

      這個只是返回相對這個widget(重載了QMouseEvent的widget)的位置。

       const Returns the position of the mouse cursor, relative to the widget that 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 the event. This is important on asynchronous window systems like X11. Whenever you move your widgets around in response to mouse events,globalPos() may differ a lot from the current pointer position QCursor::pos(), and from QWidget::mapToGlobal(pos()).

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

      返回相對顯示器的全局座標

      Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates. You can call QWidget::mapFromGlobal() to translate it to widget coordinates. Note: The position is queried from the windowing system. If mouse events are generated via other means (e.g., via QWindowSystemInterface in a unit test), those fake mouse moves will not be reflected in the returned value. Note: On platforms where there is no windowing system or cursors are not available, the returned position is based on the mouse move events generated via QWindowSystemInterface.

4、QWidget::pos() : QPoint

這個屬性獲得的是當前目前控件在父窗口中的位置,

This property holds the position of the widget within its parent widget.

If the widget is a window, the position is that of the widget on the desktop, including its frame.

When changing the position, the widget, if visible, receives a move event (moveEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.

By default, this property contains a position that refers to the origin.

Warning: Calling move() or setGeometry() inside moveEvent() can lead to infinite recursion.

See the Window Geometry documentation for an overview of geometry issues with windows.

5、const QPointF & QMouseEvent::screenPos() const

Returns the position of the mouse cursor as a QPointF, relative to the screen that received the event.

QPoint QMouseEvent::globalPos() 值相同,但是類型更高精度的QPointF

This function was introduced in Qt 5.0. 

 

本博客僅供學習使用,r

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章