QDragMoveEvent Class

QDragMoveEvent 类提供了一个在拖放操作进行时发送的事件。更多

头文件: #include <QDragMoveEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承: QDropEvent
继承于:

QDragEnterEvent

公共函数

QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, QEvent::Type type = DragMove)
void accept(const QRect &rectangle)
void accept()
QRect answerRect() const
void ignore(const QRect &rectangle)
void ignore()

详细说明

如果一个部件接受drop eventsenter events ,当拖动在其边界内时,该部件将重复接收拖动移动事件。部件应检查事件,查看它提供了哪种data ,如果合适,则调用accept() 函数接受拖放。

answerRect() 函数提供的矩形区域可用于限制向部件的某些部分投放。例如,我们可以检查矩形是否与某个子 widget 的几何图形相交,只有在这种情况下才调用acceptProposedAction() 函数。

请注意,该类的大部分功能继承自QDropEvent

另请参见 QDragEnterEvent,QDragLeaveEvent, 和QDropEvent

成员函数文档

QDragMoveEvent::QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, QEvent::Type type = DragMove)

创建所需type 的 QDragMoveEvent,表示鼠标位于 widget 中给定的位置pos

鼠标和键盘状态由buttonsmodifiers 指定,actions 描述了可能的拖放操作类型。拖放数据以 MIME 编码信息的形式在data 中传递。

警告: 请勿尝试自行创建 QDragMoveEvent。这些对象依赖于 Qt 的内部状态。

void QDragMoveEvent::accept(const QRect &rectangle)

与 accept()相同,但也会通知以后的移动,如果它们保持在 widget 上给出的rectangle 范围内,也是可以接受的。这可以提高性能,但也可能被底层系统忽略。

如果矩形为空,将连续发送拖动移动事件。如果源在定时器事件中滚动,这将非常有用。

void QDragMoveEvent::accept()

这是一个重载函数。

调用QDropEvent::accept().

QRect QDragMoveEvent::answerRect() const

如果接受,则返回 widget 中将发生下拉的矩形区域。您可以使用此信息将下拉限制在 widget 上的特定位置。

void QDragMoveEvent::ignore(const QRect &rectangle)

与 accept(constQRect&) 函数相反。在rectangle 范围内的移动是不可接受的,将被忽略。

void QDragMoveEvent::ignore()

这是一个重载函数。

调用QDropEvent::ignore().

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