本页内容

QGraphicsSceneEvent Class

QGraphicsSceneEvent 类为所有与图形视图相关的事件提供了一个基类。更多内容...

头文件: #include <QGraphicsSceneEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承自: QEvent
被继承:

QGraphicsSceneContextMenuEvent、QGraphicsSceneDragDropEvent 、QGraphicsSceneHelpEvent 、QGraphicsSceneHoverEvent 、QGraphicsSceneMouseEvent 、QGraphicsSceneMoveEvent 、QGraphicsSceneResizeEvent ,以及QGraphicsSceneWheelEvent

公共函数

virtual ~QGraphicsSceneEvent()
(since 6.2) quint64 timestamp() const
QWidget *widget() const

详细说明

当QGraphicsView 接收 Qt 鼠标、键盘和拖放事件(QMouseEvent 、QKeyEvent 、QDragEvent 等)时,它会将它们转换为 QGraphicsSceneEvent 子类的实例,并将其转发给它所显示的QGraphicsScene 。然后,场景将事件转发给相关项目。

例如,当QGraphicsView 接收到类型为MousePress的QMouseEvent (作为用户点击的响应)时,视图会通过其mousePressEvent()函数向底层的QGraphicsScene 发送类型为GraphicsSceneMousePress的QGraphicsSceneMouseEvent 。默认的QGraphicsScene::mousePressEvent()实现会确定哪个项被点击,并将事件转发给QGraphicsItem::mousePressEvent()。

诸如QGraphicsSceneMouseEvent 和QGraphicsSceneContextMenuEvent 之类的子类,会将原始QEvent 的坐标转换为屏幕坐标、场景坐标和项目坐标(参见screenPos()、scenePos()和pos())。 项目坐标由QGraphicsScene 在将事件转发至QGraphicsItem 之前设定。鼠标事件还允许获取视图接收到的最后一个事件的坐标(参见lastScreenPos(),lastScenePos() 和lastPos())。

另请参阅 QEvent 。

成员函数文档

[virtual noexcept] QGraphicsSceneEvent::~QGraphicsSceneEvent()

销毁该事件。

[since 6.2] quint64 QGraphicsSceneEvent::timestamp() const

返回原始事件的时间戳;如果原始事件未报告时间戳,则返回 0。

该函数自 Qt 6.2 起引入。

QWidget *QGraphicsSceneEvent::widget() const

返回事件的源头控件;如果事件源自另一个应用程序,则返回nullptr 。

© 2026 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.