QMouseEvent 类

QMouseEvent class contains parameters that describe a mouse event. 更多...

头: #include <QMouseEvent>
qmake: QT += gui
继承: QInputEvent

公共函数

QMouseEvent (Type type , const QPointF & localPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers )
QMouseEvent (Type type , const QPointF & localPos , const QPointF & screenPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers )
QMouseEvent (Type type , const QPointF & localPos , const QPointF & windowPos , const QPointF & screenPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers )
QMouseEvent (Type type , const QPointF & localPos , const QPointF & windowPos , const QPointF & screenPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::MouseEventSource source )
Qt::MouseButton button () const
Qt::MouseButtons buttons () const
Qt::MouseEventFlags flags () const
QPoint globalPos () const
int globalX () const
int globalY () const
const QPointF & localPos () const
QPoint pos () const
const QPointF & screenPos () const
Qt::MouseEventSource source () const
const QPointF & windowPos () const
int x () const
int y () const

额外继承成员

详细描述

QMouseEvent class contains parameters that describe a mouse event.

发生鼠标事件,当在 Widget 内按下 (或释放) 鼠标按钮 (或移动鼠标光标) 时。

才发生鼠标移动事件当按下鼠标按钮时,除非启用鼠标跟踪采用 QWidget::setMouseTracking ().

Qt 自动抓取鼠标当在 Widget 内按下鼠标按钮时;Widget 将继续接收鼠标事件,直到最后释放鼠标按钮。

鼠标事件包含特殊接受标志 (指示接收者是否想要事件)。应该调用 ignore () 若鼠标事件未被 Widget 所处理。鼠标事件会沿父级 Widget 链向上传播,直到小部件接受它采用 accept (),或由事件过滤器消耗掉它。

注意: 若鼠标事件被传播给 widget 其中 Qt::WA_NoMousePropagation 有设置,该鼠标事件将不会沿父级 Widget 链向上进一步传播。

可以找到键盘修饰符键的状态通过调用 modifiers() 函数,继承自 QInputEvent .

函数 pos (), x (),和 y () give the cursor position relative to the widget that receives the mouse event. If you move the widget as a result of the mouse event, use the global position returned by globalPos () 以避免晃动。

QWidget::setEnabled () 函数可用于启用 (或禁用) 小部件的鼠标事件和键盘事件。

重实现 QWidget 事件处理程序, QWidget::mousePressEvent (), QWidget::mouseReleaseEvent (), QWidget::mouseDoubleClickEvent (),和 QWidget::mouseMoveEvent () 以在自己的 Widget 中接收鼠标事件。

另请参阅 QWidget::setMouseTracking (), QWidget::grabMouse (),和 QCursor::pos ().

成员函数文档编制

QMouseEvent:: QMouseEvent ( Type type , const QPointF & localPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers )

构造鼠标事件对象。

type 参数必须是某一 QEvent::MouseButtonPress , QEvent::MouseButtonRelease , QEvent::MouseButtonDblClick ,或 QEvent::MouseMove .

localPos 是鼠标光标相对于接收 Widget 或项的位置。窗口位置会被设为相同值如 localPos button 导致给定值事件来自 Qt::MouseButton 枚举。若事件 type is MouseMove ,此事件的相应按钮为 Qt::NoButton 。事件发生时的鼠标和键盘状态的指定通过 buttons and modifiers .

screenPos () 被初始化为 QCursor::pos (),可能不合适。使用其它构造函数以明确指定全局位置。

QMouseEvent:: QMouseEvent ( Type type , const QPointF & localPos , const QPointF & screenPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers )

构造鼠标事件对象。

type 参数必须是 QEvent::MouseButtonPress , QEvent::MouseButtonRelease , QEvent::MouseButtonDblClick ,或 QEvent::MouseMove .

localPos 是鼠标光标相对于接收 Widget 或项的位置。按屏幕坐标的光标位置的指定由 screenPos 。窗口位置会被设为相同值如 localPos button 导致给定值事件来自 Qt::MouseButton 枚举。若事件 type is MouseMove ,此事件的相应按钮为 Qt::NoButton . buttons 是事件发生时所有按钮的状态, modifiers 是所有键盘修饰符的状态。

QMouseEvent:: QMouseEvent ( Type type , const QPointF & localPos , const QPointF & windowPos , const QPointF & screenPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers )

构造鼠标事件对象。

type 参数必须是 QEvent::MouseButtonPress , QEvent::MouseButtonRelease , QEvent::MouseButtonDblClick ,或 QEvent::MouseMove .

localPos , windowPos and screenPos specify the mouse cursor's position relative to the receiving widget or item, window, and screen, respectively.

button 导致给定值事件来自 Qt::MouseButton 枚举。若事件 type is MouseMove ,此事件的相应按钮为 Qt::NoButton . buttons 是事件发生时所有按钮的状态, modifiers 是所有键盘修饰符的状态。

QMouseEvent:: QMouseEvent ( Type type , const QPointF & localPos , const QPointF & windowPos , const QPointF & screenPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , Qt::MouseEventSource source )

Default constructs an instance of QMouseEvent.

Qt::MouseButton QMouseEvent:: button () const

返回导致事件的按钮。

注意:返回值始终是 Qt::NoButton 对于鼠标移动事件而言。

另请参阅 buttons () 和 Qt::MouseButton .

Qt::MouseButtons QMouseEvent:: buttons () const

Returns the button state when the event was generated. The button state is a combination of Qt::LeftButton , Qt::RightButton , Qt::MidButton using the OR operator. For mouse move events, this is all buttons that are pressed down. For mouse press and double click events this includes the button that caused the event. For mouse release events this excludes the button that caused the event.

另请参阅 button () 和 Qt::MouseButton .

Qt::MouseEventFlags QMouseEvent:: flags () const

返回鼠标事件标志。

鼠标事件标志提供有关鼠标事件的额外信息。

该函数在 Qt 5.3 引入。

另请参阅 Qt::MouseEventFlag and QGraphicsSceneMouseEvent::flags ().

QPoint QMouseEvent:: globalPos () const

返回鼠标光标的全局位置 在事件发生时 . 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 ()).

另请参阅 globalX () 和 globalY ().

int QMouseEvent:: globalX () const

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

另请参阅 globalY () 和 globalPos ().

int QMouseEvent:: globalY () const

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

另请参阅 globalX () 和 globalPos ().

const QPointF &QMouseEvent:: localPos () const

将鼠标光标位置返回作为 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 () 以避免晃动。

该函数在 Qt 5.0 引入。

另请参阅 x (), y (), windowPos (),和 screenPos ().

QPoint QMouseEvent:: pos () const

返回鼠标光标的位置,相对于接收事件的 Widget。

If you move the widget as a result of the mouse event, use the global position returned by globalPos () 以避免晃动。

另请参阅 x (), y (),和 globalPos ().

const QPointF &QMouseEvent:: screenPos () const

将鼠标光标位置返回作为 QPointF , relative to the screen that received the event.

该函数在 Qt 5.0 引入。

另请参阅 x (), y (), pos (), localPos (),和 windowPos ().

Qt::MouseEventSource QMouseEvent:: source () const

返回鼠标事件来源的有关信息。

鼠标事件来源可以用于区分真正和和人造的鼠标事件。后者是由操作系统或 Qt 自身从触摸事件合成的事件。

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

该函数在 Qt 5.3 引入。

另请参阅 Qt::MouseEventSource and QGraphicsSceneMouseEvent::source ().

const QPointF &QMouseEvent:: windowPos () const

将鼠标光标位置返回作为 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 () 以避免晃动。

该函数在 Qt 5.0 引入。

另请参阅 x (), y (), pos (), localPos (),和 screenPos ().

int QMouseEvent:: x () const

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

另请参阅 y () 和 pos ().

int QMouseEvent:: y () const

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

另请参阅 x () 和 pos ().