Line | |
---|
1 | #include "DropLineEdit.h"
|
---|
2 |
|
---|
3 | DropLineEdit::DropLineEdit(QWidget *parent) : QLineEdit(parent)
|
---|
4 | {
|
---|
5 | //setDragDropMode(QAbstractItemView::DropOnly);
|
---|
6 | setAcceptDrops(true);
|
---|
7 | }
|
---|
8 |
|
---|
9 | void DropLineEdit::dragEnterEvent(QDragEnterEvent *event) {
|
---|
10 |
|
---|
11 | const QMimeData* mimeData = event->mimeData();
|
---|
12 |
|
---|
13 | // We only accept if our widget is enabled and it is only one file
|
---|
14 | if(
|
---|
15 | !this->isEnabled() ||
|
---|
16 | mimeData->urls().size() != 1 ||
|
---|
17 | // checks if it is a file (folders are ignored)
|
---|
18 | QDir(mimeData->urls().at(0).toLocalFile()).exists()
|
---|
19 | )
|
---|
20 | {
|
---|
21 | event->ignore();
|
---|
22 | }
|
---|
23 | else{
|
---|
24 | event->acceptProposedAction();
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | void DropLineEdit::dragMoveEvent(QDragMoveEvent *event) {
|
---|
29 | event->acceptProposedAction();
|
---|
30 | }
|
---|
31 |
|
---|
32 | void DropLineEdit::dropEvent(QDropEvent *event) {
|
---|
33 |
|
---|
34 | const QMimeData* mimeData = event->mimeData();
|
---|
35 |
|
---|
36 | event->acceptProposedAction();
|
---|
37 |
|
---|
38 | QStringList pathList = QStringList();
|
---|
39 |
|
---|
40 | if (mimeData->hasUrls())
|
---|
41 | {
|
---|
42 | this->setText(mimeData->urls().at(0).toLocalFile());
|
---|
43 | }
|
---|
44 |
|
---|
45 | }
|
---|
46 |
|
---|
47 | void DropLineEdit::dragLeaveEvent(QDragLeaveEvent *event) {
|
---|
48 | event->accept();
|
---|
49 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.