QGraphicsSceneEvent类为所有图形视图相关事件提供基类。
Header: | #include <QGraphicsSceneEvent> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
Inherits: | QEvent |
Inherited By: |
【详细描述】
当一个QGraphicsView对象接收到鼠标、键盘和拖放事件(QMouseEvent, QKeyEvent, QDragEvent)时,会将这些事件转换为QGraphicsSceneEvent子类的实例,并转发到它显示的 QGraphicsScene实例,然后这个场景将事件转发到相关项目。
例如,当 QGraphicsView接收到MousePress类型的QMouseEvent作为对用户单击的响应时,视图会通过其mousePressEvent ()函数将GraphicsSceneMousePress 类型的 QGraphicsSceneMouseEvent发送到底层QGraphicsScene。默认的 QGraphicsScene::mousePressEvent()实现了确定单击了哪个项目并将事件转发到 QGraphicsItem::mousePressEvent()。
QGraphicsSceneMouseEvent和QGraphicsSceneContextMenuEvent等子类在屏幕、场景和项目坐标中提供原始QEvent坐标(请参阅 screenPos()、scenePos()和pos())。项目坐标由 QGraphicsScene在将事件转发到QGraphicsItem之前设置。鼠标事件还增加了从视图接收的最后一个事件中检索坐标的可能性(请参阅 lastScreenPos ()、 lastScenePos () 和 lastPos ())。
另请参见 QEvent。
【公有函数】
virtual | ~QGraphicsSceneEvent() | 销毁事件。 |
quint64 | timestamp() const | 返回原始事件的时间戳,如果原始事件未报告时间戳,则返回 0。 |
QWidget * | widget() const | 返回事件源自的控件,如果事件源自另一个应用程序,则返回nullptr。 |