QGraphicsSceneMouseEvent Class

QGraphicsSceneMouseEvent 类提供图形视图框架中的鼠标事件。更多

Header: #include <QGraphicsSceneMouseEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: QGraphicsSceneEvent

公共函数

virtual ~QGraphicsSceneMouseEvent()
Qt::MouseButton button() const
QPointF buttonDownPos(Qt::MouseButton button) const
QPointF buttonDownScenePos(Qt::MouseButton button) const
QPoint buttonDownScreenPos(Qt::MouseButton button) const
Qt::MouseButtons buttons() const
Qt::MouseEventFlags flags() const
QPointF lastPos() const
QPointF lastScenePos() const
QPoint lastScreenPos() const
Qt::KeyboardModifiers modifiers() const
QPointF pos() const
QPointF scenePos() const
QPoint screenPos() const
Qt::MouseEventSource source() const

详细说明

QGraphicsView 接收到QMouseEvent 时,它会将其转换为 QGraphicsSceneMouseEvent。然后,该事件会被转发到与视图相关联的QGraphicsScene 。如果场景没有处理该事件,视图可能会使用它,例如用于DragMode

除了包含事件的项目、场景和屏幕坐标(如pos(),scenePos(), 和screenPos()), 鼠标事件还包含视图接收到的上一个鼠标事件的坐标。这些坐标可以通过lastPos(),lastScreenPos() 和lastScenePos() 获取。

另请参阅 QGraphicsSceneContextMenuEvent,QGraphicsSceneHoverEvent,QGraphicsSceneWheelEventQMouseEvent

成员函数文档

[virtual noexcept] QGraphicsSceneMouseEvent::~QGraphicsSceneMouseEvent()

摧毁事件。

Qt::MouseButton QGraphicsSceneMouseEvent::button() const

返回导致事件发生的鼠标按钮(如果有)。

另请参阅 buttons() 和modifiers()。

QPointF QGraphicsSceneMouseEvent::buttonDownPos(Qt::MouseButton button) const

以项目坐标方式返回鼠标指针在指定button 上的位置。

另请参阅 buttonDownScenePos()、buttonDownScreenPos() 和pos()。

QPointF QGraphicsSceneMouseEvent::buttonDownScenePos(Qt::MouseButton button) const

以场景坐标方式返回鼠标光标在指定button 处被点击的位置。

另请参阅 buttonDownPos()、buttonDownScreenPos() 和scenePos()。

QPoint QGraphicsSceneMouseEvent::buttonDownScreenPos(Qt::MouseButton button) const

以屏幕坐标方式返回鼠标光标在指定button 上的点击位置。

另请参阅 screenPos()、buttonDownPos() 和buttonDownScenePos()。

Qt::MouseButtons QGraphicsSceneMouseEvent::buttons() const

返回事件发送时按下的鼠标键组合。

另请参阅 button() 和modifiers()。

Qt::MouseEventFlags QGraphicsSceneMouseEvent::flags() const

返回鼠标事件标志。

鼠标事件标志提供了鼠标事件的附加信息。

另请参阅 Qt::MouseEventFlagQMouseEvent::flags()。

QPointF QGraphicsSceneMouseEvent::lastPos() const

以项目坐标形式返回最后记录的鼠标指针位置。

另请参阅 lastScenePos()、lastScreenPos() 和pos()。

QPointF QGraphicsSceneMouseEvent::lastScenePos() const

以场景坐标形式返回上次记录的鼠标指针位置。最后记录的位置是创建该事件的视图接收到的上一个鼠标事件的位置。

另请参阅 lastPos()、lastScreenPos() 和scenePos()。

QPoint QGraphicsSceneMouseEvent::lastScreenPos() const

以屏幕坐标形式返回上次记录的鼠标指针位置。最后记录的位置是创建该事件的视图接收到的上一个鼠标事件的位置。

另请参阅 lastPos()、lastScenePos() 和screenPos()。

Qt::KeyboardModifiers QGraphicsSceneMouseEvent::modifiers() const

返回事件发送时使用的键盘修饰符。

另请参阅 buttons() 和button()。

QPointF QGraphicsSceneMouseEvent::pos() const

返回鼠标指针在项目坐标中的位置。

另请参阅 scenePos()、screenPos() 和lastPos()。

QPointF QGraphicsSceneMouseEvent::scenePos() const

返回鼠标指针在场景坐标中的位置。

另请参阅 pos()、screenPos() 和lastScenePos()。

QPoint QGraphicsSceneMouseEvent::screenPos() const

返回鼠标光标在屏幕坐标中的位置。

另请参阅 pos()、scenePos() 和lastScreenPos()。

Qt::MouseEventSource QGraphicsSceneMouseEvent::source() const

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

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

另请参阅 Qt::MouseEventSourceQMouseEvent::source()。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.