QMimeData 【Qt帮助文档】

 

http://doc.qt.nokia.com/latest/qmimedata.html

 

QMimeData Class Reference

 

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:

  1. Custom data can be stored directly in a QMimeData object as a QByteArray using setData(). For example:
     QByteArray csvData = ...;
    
     QMimeData *mimeData = new QMimeData;
     mimeData->setData("text/csv", csvData);
  2. We can subclass QMimeData and reimplement hasFormat(), formats(), and retrieveData().
  3. If the drag and drop operation occurs within a single application, we can subclass QMimeData and add extra data in it, and use a qobject_cast() in the receiver's drop event handler. For example:
     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)
         }
     }

Platform-Specific MIME Types

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.

你可能感兴趣的:(windows,object,application,文档,qt,Types)