QGraphicsSceneDragDropEvent Class
QGraphicsSceneDragDropEvent 类为图形视图框架中的拖放操作提供了事件。更多内容...
| 头文件: | #include <QGraphicsSceneDragDropEvent> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 继承自: | QGraphicsSceneEvent |
公共函数
| virtual | ~QGraphicsSceneDragDropEvent() |
| void | acceptProposedAction() |
| Qt::MouseButtons | buttons() const |
| Qt::DropAction | dropAction() const |
| const QMimeData * | mimeData() const |
| Qt::KeyboardModifiers | modifiers() const |
| QPointF | pos() const |
| Qt::DropActions | possibleActions() const |
| Qt::DropAction | proposedAction() const |
| QPointF | scenePos() const |
| QPoint | screenPos() const |
| void | setDropAction(Qt::DropAction action) |
| QWidget * | source() const |
详细说明
QGraphicsView 继承了QWidget 提供的拖放功能。当接收到拖放事件时,它会将其转换为QGraphicsSceneDragDropEvent。
`QGraphicsSceneDragDropEvent` 存储 `GraphicsSceneDragEnter`、`GraphicsSceneDragLeave`、`GraphicsSceneDragMove` 或 `GraphicsSceneDrop` 类型的事件。
QGraphicsSceneDragDropEvent 包含鼠标光标在项目、场景和屏幕坐标系中的位置;可以通过pos()、scenePos() 和screenPos() 获取这些信息。
场景会将事件发送给鼠标光标下方第一个支持拖放操作的QGraphicsItem ;可通过setAcceptDrops()将图形项设置为支持拖放操作。
成员函数文档
[virtual noexcept] QGraphicsSceneDragDropEvent::~QGraphicsSceneDragDropEvent()
销毁该对象。
void QGraphicsSceneDragDropEvent::acceptProposedAction()
将建议的操作设为已接受,即“拖放”操作被设为建议的操作。这等同于:
setDropAction(proposedAction());使用此函数时,不应调用 `accept()`。
另请参阅 dropAction()、setDropAction() 以及proposedAction()。
Qt::MouseButtons QGraphicsSceneDragDropEvent::buttons() const
返回一个Qt::MouseButtons 值,用于指示在生成此鼠标事件时按下了哪些鼠标按钮。
另请参阅 Qt::MouseButtons 。
Qt::DropAction QGraphicsSceneDragDropEvent::dropAction() const
返回此次拖放操作中执行的操作。该值应由拖放目标设置,并由 `QDrag::exec()` 方法返回。
另请参阅 setDropAction() 和acceptProposedAction()。
const QMimeData *QGraphicsSceneDragDropEvent::mimeData() const
该函数返回事件的 MIME 数据。
Qt::KeyboardModifiers QGraphicsSceneDragDropEvent::modifiers() const
返回在创建拖放事件时被按下的键盘修饰键。
另请参阅 Qt::KeyboardModifiers 。
QPointF QGraphicsSceneDragDropEvent::pos() const
返回事件相对于发送该事件的视图的鼠标位置。
另请参阅 QGraphicsView 、screenPos() 和scenePos()。
Qt::DropActions QGraphicsSceneDragDropEvent::possibleActions() const
返回拖放操作可能产生的释放动作。
另请参阅 Qt::DropActions 。
Qt::DropAction QGraphicsSceneDragDropEvent::proposedAction() const
返回建议的(即首选的)拖放操作。该操作必须是possibleActions() 中定义的可能操作之一。
另请参阅 Qt::DropAction 和possibleActions()。
QPointF QGraphicsSceneDragDropEvent::scenePos() const
返回鼠标在场景坐标系中的位置。
QPoint QGraphicsSceneDragDropEvent::screenPos() const
返回鼠标相对于屏幕的位置。
void QGraphicsSceneDragDropEvent::setDropAction(Qt::DropAction action)
该函数允许“drop”操作的接收方将执行的“drop”操作设置为action ,该值应为possible actions 中的一个。若使用此函数,请调用accept() 而非acceptProposedAction() 。
另请参阅 dropAction()、accept() 和possibleActions()。
QWidget *QGraphicsSceneDragDropEvent::source() const
该函数返回创建了QGraphicsSceneDragDropEvent 的QGraphicsView 。
© 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.