blob: 36cbdefa1ca56a5c7de39a8bf706fbe75501674a (
plain)
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
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
//! [0]
void MyWidget::dragEnterEvent(QDragEnterEvent *event)
{
if (event->mimeData()->hasUrls())
event->acceptProposedAction();
}
void MyWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasUrls()) {
foreach (QUrl url, event->mimeData()->urls()) {
...
}
}
}
//! [0]
//! [1]
QByteArray csvData = ...;
QMimeData *mimeData = new QMimeData;
mimeData->setData("text/csv", csvData);
//! [1]
//! [2]
void MyWidget::dropEvent(QDropEvent *event)
{
const MyMimeData *myData =
qobject_cast<const MyMimeData *>(event->mimeData());
if (myData) {
// access myData's data directly (not through QMimeData's API)
}
}
//! [2]
//! [3]
application/x-qt-windows-mime;value="<custom type>"
//! [3]
//! [4]
application/x-qt-windows-mime;value="FileGroupDescriptor"
application/x-qt-windows-mime;value="FileContents"
//! [4]
//! [5]
if (event->mimeData()->hasImage()) {
QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());
...
}
//! [5]
//! [6]
mimeData->setImageData(QImage("beautifulfjord.png"));
//! [6]
//! [7]
if (event->mimeData()->hasColor()) {
QColor color = qvariant_cast<QColor>(event->mimeData()->colorData());
...
}
//! [7]
//! [8]
application/x-qt-windows-mime;value="FileContents";index=0
application/x-qt-windows-mime;value="FileContents";index=1
//! [8]
|