QDragMoveEvent Class
QDragMoveEvent 类提供了一种事件,该事件在拖放操作进行期间触发。更多内容...
| 头文件: | #include <QDragMoveEvent> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
| 继承自: | QDropEvent |
| 被继承者: |
- 所有成员列表(包括继承的成员)
- 已弃用的成员
- QDragMoveEvent 属于事件类。
公共函数
| QDragMoveEvent(QPointF 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() |
受保护的函数
| QDragMoveEvent(QDragMoveEvent &&) | |
| QDragMoveEvent & | operator=(QDragMoveEvent &&) |
| QDragMoveEvent & | operator=(const QDragMoveEvent &other) |
详细说明
如果小部件接受drop events 和enter events ,那么在拖动操作处于其边界内时,该小部件将反复接收拖动事件。小部件应检查该事件以确定其提供的data 类型,并在适当的情况下调用accept()函数来接受释放操作。
answerRect() 函数提供的矩形可用于将拖放操作限制在小部件的特定区域内。例如,我们可以检查该矩形是否与某个子小部件的几何区域相交,并仅在相交时才调用acceptProposedAction()。
请注意,该类的大部分功能继承自 `QDropEvent`。
另请参阅 QDragEnterEvent 、QDragLeaveEvent 和QDropEvent 。
成员函数文档
QDragMoveEvent::QDragMoveEvent(QPointF pos, Qt::DropActions actions, const QMimeData *data, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, QEvent::Type type = DragMove)
创建一个具有所需type 的QDragMoveEvent,表示鼠标位于小部件内给定的位置pos 处。
鼠标和键盘状态由buttons 和modifiers 指定,而actions 描述了可能的拖放操作类型。拖放数据作为MIME编码信息通过data 传递。
警告:请 勿尝试自行创建 QDragMoveEvent。这些对象依赖于 Qt 的内部状态。
[protected delete] QDragMoveEvent::QDragMoveEvent(QDragMoveEvent &&)
通过移动构造一个QDragMoveEvent 的实例。该函数已被删除。
void QDragMoveEvent::accept(const QRect &rectangle)
与 accept() 相同,但还会通知系统:只要后续移动操作仍处于小部件指定的rectangle 范围内,这些操作也将被接受。这可以提高性能,但底层系统也可能忽略此通知。
如果该矩形为空,则将持续发送拖动事件。当源对象在定时器事件中滚动时,此功能非常有用。
void QDragMoveEvent::accept()
调用QDropEvent::accept()。
这是一个重载函数。
QRect QDragMoveEvent::answerRect() const
返回小部件中若操作被接受时将发生拖放操作的矩形区域。您可以利用此信息将拖放操作限制在小部件的特定位置。
void QDragMoveEvent::ignore(const QRect &rectangle)
这是 accept(constQRect&) 函数的反向操作。rectangle 中的移动操作不可接受,将被忽略。
void QDragMoveEvent::ignore()
调用QDropEvent::ignore()。
这是一个重载函数。
[protected delete] QDragMoveEvent &QDragMoveEvent::operator=(QDragMoveEvent &&)
将other 按移动赋值方式赋值给此QDragMoveEvent 实例。该函数已被删除。
[noexcept protected default] QDragMoveEvent &QDragMoveEvent::operator=(const QDragMoveEvent &other)
将other 复制并赋值给该QDragMoveEvent 实例。
© 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.