-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathdraglistwidget.cpp
105 lines (90 loc) · 2.75 KB
/
draglistwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "draglistwidget.h"
DragListWidget::DragListWidget(QWidget *parent):QListWidget(parent)
{
setAcceptDrops(true);
}
DragListWidget::~DragListWidget()
{
}
//bool DragListWidget::eventFilter(QObject *obj, QEvent *eve)
//{
// if(obj == )
//}
//void DragListWidget::mousePressEvent(QMouseEvent *event)
//{
// //确保左键拖拽.
// if (event->button() == Qt::LeftButton)
// {
// qDebug()<<"mousePressEvent mousePressEvent mousePressEvent";
// //先保存拖拽的起点.
// dragPoint = event->pos();
// //保留被拖拽的项.
// dragItem = this->itemAt(event->pos());
// }
// //保留原QListWidget部件的鼠标点击操作.
// QListWidget::mousePressEvent(event);
//}
//void DragListWidget::mouseMoveEvent(QMouseEvent *event)
//{
// //确保按住左键移动.
// if (event->buttons() & Qt::LeftButton)
// {
// QPoint temp = event->pos() - dragPoint;
// //只有这个长度大于默认的距离,才会被系统认为是形成拖拽的操作.
// if (temp.manhattanLength() > QApplication::startDragDistance())
// {
// QDrag *drag = new QDrag(this);
// QMimeData *mimeData = new QMimeData;
// mimeData->setText(dragItem->text());
// drag->setMimeData(mimeData);
// auto action = drag->exec(Qt::CopyAction | Qt::MoveAction);
// if (action == (Qt::CopyAction) || (action == Qt::MoveAction))
// {
// //当成功拖拽后,删除拖拽项.
// auto i = this->takeItem(this->row(dragItem));
// delete i;
// }
// }
// }
// QListWidget::mouseMoveEvent(event);
//}
//void DragListWidget::mouseReleaseEvent(QMouseEvent *event)
//{
// QListWidget::mouseReleaseEvent(event);
//}
void DragListWidget::dragEnterEvent(QDragEnterEvent *event)
{
// 判断拖拽文件类型,文件名 接收该动作
if(!event->mimeData()->hasFormat("text/uri-list"))
{
event->setDropAction(Qt::CopyAction);
event->acceptProposedAction();
}
QListWidget::dragEnterEvent(event);
}
void DragListWidget::dragMoveEvent(QDragMoveEvent *event)
{
// event->setDropAction(Qt::MoveAction);
}
void DragListWidget::dragLeaveEvent(QDragLeaveEvent *event)
{
// QListWidget::dragLeaveEvent(event);
}
void DragListWidget::dropEvent(QDropEvent *event)
{
// 判断拖拽文件类型,文件名 接收该动作
if(!event->mimeData()->hasFormat("text/uri-list"))
{
return ;
}
auto urls = event->mimeData()->urls();
qDebug()<<"urls urls urls urls urls urls urls:"<<urls;
QStringList localpath;
for(auto &url : urls)
{
localpath << url.toLocalFile();
}
if(!localpath.isEmpty())
{
}
}