http://doc.qt.nokia.com/latest/qmimedata.html
For example, if your write a widget that accepts URL drags, you would end up writing code like this:
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()) { ... } } }
There are three approaches for storing custom data in a QMimeData object:
QByteArray csvData = ...;
QMimeData *mimeData = new QMimeData;
mimeData->setData("text/csv", csvData);
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)
}
}
On Windows, formats() will also return custom formats available in the MIME data, using the x-qt-windows-mime subtype to indicate that they represent data in non-standard formats. The formats will take the following form:
application/x-qt-windows-mime;value="<custom type>"
The following are examples of custom MIME types:
application/x-qt-windows-mime;value="FileGroupDescriptor" application/x-qt-windows-mime;value="FileContents"
The value declaration of each format describes the way in which the data is encoded.
On Windows, the MIME format does not always map directly to the clipboard formats. Qt provides QWindowsMime to map clipboard formats to open-standard MIME formats. Similarly, the QMacPasteboardMime maps MIME to Mac flavors.
See also QClipboard, QDragEnterEvent, QDragMoveEvent, QDropEvent, QDrag, QWindowsMime, QMacPasteboardMime, and Drag and Drop.