Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_corelib_kernel_qmimedata.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
6#include <QMimeData>
7#include <QDragEnterEvent>
8#include <QImage>
9
10namespace MyNamespace
11{
13 {
14 public:
15 void dragEnterEvent(QDragEnterEvent *event);
16 void dropEvent(QDropEvent *event);
17 };
18
19 //! [0]
20 void MyWidget::dragEnterEvent(QDragEnterEvent *event)
21 {
22 if (event->mimeData()->hasUrls())
23 event->acceptProposedAction();
24 }
25
26 void MyWidget::dropEvent(QDropEvent *event)
27 {
28 if (event->mimeData()->hasUrls()) {
29 foreach (QUrl url, event->mimeData()->urls()) {
30 //...
31 }
32 }
33 }
34 //! [0]
35}
36
37void wrap()
38{
39 QByteArray something = "";
40 //! [1]
41 QByteArray csvData = something;
42
43 QMimeData *mimeData = new QMimeData;
44 mimeData->setData("text/csv", csvData);
45 //! [1]
46}
47
49{
50
52 {
53 public:
54 void dropEvent(QDropEvent *event);
55 };
56
57 class MyMimeData : public QMimeData
58 {
60 };
61
62 //! [2]
63 void MyWidget::dropEvent(QDropEvent *event)
64 {
65 const MyMimeData *myData =
66 qobject_cast<const MyMimeData *>(event->mimeData());
67 if (myData) {
68 // access myData's data directly (not through QMimeData's API)
69 }
70 }
71 //! [2]
72}
73
74#if PRO_FILE
75//! [3]
76application/x-qt-windows-mime;value="<custom type>"
77//! [3]
78
79
80//! [4]
81application/x-qt-windows-mime;value="FileGroupDescriptor"
82application/x-qt-windows-mime;value="FileContents"
83//! [4]
84#endif
85
86void examples(QDropEvent *event, QMimeData *mimeData)
87{
88 {
89 //! [5]
90 if (event->mimeData()->hasImage()) {
91 QImage image = qvariant_cast<QImage>(event->mimeData()->imageData());
92 //...
93 }
94 //! [5]
95 }
96
97 {
98 //! [6]
99 mimeData->setImageData(QImage("beautifulfjord.png"));
100 //! [6]
101 }
102
103 {
104 //! [7]
105 if (event->mimeData()->hasColor()) {
106 QColor color = qvariant_cast<QColor>(event->mimeData()->colorData());
107 //...
108 }
109 //! [7]
110 }
111}
112
113#if PRO_FILE
114//! [8]
115application/x-qt-windows-mime;value="FileContents";index=0
116application/x-qt-windows-mime;value="FileContents";index=1
117//! [8]
118#endif
void dragEnterEvent(QDragEnterEvent *event)
[0]
void dropEvent(QDropEvent *event)
[2]
void wrap()
[23]
void examples(QObject *obj, QObject *pushButton)