-
Notifications
You must be signed in to change notification settings - Fork 1
/
qcustomlineedit.cpp
48 lines (37 loc) · 1.05 KB
/
qcustomlineedit.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
#include <QtGui>
#include "qcustomlineedit.h"
QCustomLineEdit::QCustomLineEdit(QWidget *parent) : QLineEdit(parent)
{
}
QCustomLineEdit::~QCustomLineEdit()
{
}
void QCustomLineEdit::dragEnterEvent(QDragEnterEvent *event)
{
// accept just text/uri-list mime format
if (event->mimeData()->hasFormat("text/uri-list"))
{
event->acceptProposedAction();
}
}
void QCustomLineEdit::dropEvent(QDropEvent *event)
{
QList<QUrl> urlList;
QString fName;
QFileInfo info;
if(event->mimeData()->hasUrls())
{
urlList = event->mimeData()->urls(); // returns list of QUrls
// if just text was dropped, urlList is empty (size == 0)
if(urlList.size() > 0) // if at least one QUrl is present in list
{
fName = urlList[0].toLocalFile(); // convert first QUrl to local path
info.setFile(fName); // information about file
if(info.isFile())
{
setText(fName); // if is file, setText
}
}
}
event->acceptProposedAction();
}