QListWidget、QTreeWidget、QTableWidget的拖放实验
QAbstractItemView::DragDropMode 的枚举值
QAbstractItemView::NoDragDrop | 0 | 组件不支持拖放操作 |
QAbstractItemView::DragOnly | 1 | 组件只支持拖动操作 |
QAbstractItemView::DropOnly | 2 | 组件只支持放置操作 |
QAbstractItemView::DragDrop | 3 | 组件支持拖放操作 |
QAbstractItemView::InternalMove | 4 | 组件只支持内部项的移动操作,例如目录树内节点的移动操作 |
Qt::DropAction 的枚举值
Qt::CopyAction | 1 | 将数据复制到放置点组件处 |
Qt::MoveAction | 2 | 将数据从拖动点组件处移动到放置点组件处 |
Qt::LinkAction | 4 | 在拖动点组件和放置点组件之间建立数据连接 |
Qt::IgnoreAction | 0 | 对数据不进行任何操作 |
效果
DragDropItemExample.h
#ifndef DRAGDROPITEMEXAMPLE_H
#define DRAGDROPITEMEXAMPLE_H
#include <QWidget>
#include <QAbstractItemView>
#include <QGroupBox>
#include <QEvent>
namespace Ui {
class DragDro