QMouseEvent 类

QMouseEvent 类包含鼠标事件的描述参数。 更多...

Header: #include <QMouseEvent>
CMake: find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QSinglePointEvent

公共函数

QMouseEvent (QEvent::Type type , const QPointF & localPos , const QPointF & scenePos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())
QMouseEvent (QEvent::Type type , const QPointF & localPos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())
QMouseEvent (QEvent::Type type , const QPointF & localPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())
Qt::MouseEventFlags flags () const
QPoint globalPos () const
int globalX () const
int globalY () const
QPointF localPos () const
QPoint pos () const
QPointF screenPos () const
QPointF windowPos () const
int x () const
int y () const

详细描述

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

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

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

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

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

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

position () 函数给出相对接收鼠标事件的 Widget 或项的光标位置。若因鼠标事件导致移动 Widget,使用的全局位置返回通过 globalPosition () 以避免晃动。

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

重实现 QWidget 事件处理程序, QWidget::mousePressEvent (), QWidget::mouseReleaseEvent (), QWidget::mouseDoubleClickEvent (),和 QWidget::mouseMoveEvent () to receive mouse events in your own widgets.

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

成员函数文档编制

QMouseEvent:: QMouseEvent ( QEvent::Type type , const QPointF & localPos , const QPointF & scenePos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())

构造鼠标事件对象。

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

The points localPos , scenePos and globalPos specify the mouse cursor's position relative to the receiving widget or item, window, and screen or desktop, respectively.

button that caused the event is given as a value from the Qt::MouseButton 枚举。若事件 type is MouseMove , the appropriate button for this event is Qt::NoButton . buttons is the state of all buttons at the time of the event, modifiers is the state of all keyboard modifiers.

QMouseEvent:: QMouseEvent ( QEvent::Type type , const QPointF & localPos , const QPointF & globalPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())

构造鼠标事件对象源自 device .

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

localPos is the mouse cursor's position relative to the receiving widget or item. The cursor's position in screen coordinates is specified by globalPos . The window position is set to the same value as localPos button that caused the event is given as a value from the Qt::MouseButton 枚举。若事件 type is MouseMove , the appropriate button for this event is Qt::NoButton . buttons is the state of all buttons at the time of the event, modifiers the state of all keyboard modifiers.

QMouseEvent:: QMouseEvent ( QEvent::Type type , const QPointF & localPos , Qt::MouseButton button , Qt::MouseButtons buttons , Qt::KeyboardModifiers modifiers , const QPointingDevice * device = QPointingDevice::primaryPointingDevice())

构造鼠标事件对象源自 device .

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

localPos is the mouse cursor's position relative to the receiving widget or item. The window position is set to the same value as localPos button that caused the event is given as a value from the Qt::MouseButton 枚举。若事件 type is MouseMove , the appropriate button for this event is Qt::NoButton . The mouse and keyboard states at the time of the event are specified by buttons and modifiers .

globalPosition () 被初始化为 QCursor::pos (), which may not be appropriate. Use the other constructor to specify the global position explicitly.

[since 5.3] Qt::MouseEventFlags QMouseEvent:: flags () const

返回鼠标事件标志。

The mouse event flags provide additional information about a mouse event.

该函数在 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 ().

[since 5.0] 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

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 () 以避免晃动。

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

[since 5.0] QPointF QMouseEvent:: screenPos () const

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

该函数在 Qt 5.0 引入。

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

[since 5.0] 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 ().