QGraphicsSceneDragDropEvent Class
QGraphicsSceneDragDropEvent 类为图形视图框架中的拖放提供事件。更多
Header: | #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 继承了 提供的拖放功能。当接收到拖放事件时,它会将其转换为 QGraphicsSceneDragDropEvent。QWidget
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)
此函数可让下拉操作的接收方将下拉操作设置为action ,而下拉操作应是possible actions 中的一个。如果使用此函数,请调用accept()
,而不是acceptProposedAction()
。
另请参阅 dropAction()、accept() 和possibleActions()。
QWidget *QGraphicsSceneDragDropEvent::source() const
该函数返回创建QGraphicsSceneDragDropEvent 的QGraphicsView 。
© 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.