QGraphicsSceneEvent Class
QGraphicsSceneEvent 类为所有图形视图相关事件提供了一个基类。更多
Header: | #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 。
© 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.