The PySide.QtCore.QMimeData class provides a container for data that records information about its MIME type.
PySide.QtCore.QMimeData is used to describe information that can be stored in the clipboard , and transferred via the drag and drop mechanism. PySide.QtCore.QMimeData objects associate the data that they hold with the corresponding MIME types to ensure that information can be safely transferred between applications, and copied around within the same application.
PySide.QtCore.QMimeData objects are usually created using new and supplied to PySide.QtGui.QDrag or PySide.QtGui.QClipboard objects. This is to enable Qt to manage the memory that they use.
A single PySide.QtCore.QMimeData object can store the same data using several different formats at the same time. The PySide.QtCore.QMimeData.formats() function returns a list of the available formats in order of preference. The PySide.QtCore.QMimeData.data() function returns the raw data associated with a MIME type, and PySide.QtCore.QMimeData.setData() allows you to set the data for a MIME type.
For the most common MIME types, PySide.QtCore.QMimeData provides convenience functions to access the data:
For example, if your write a widget that accepts URL drags, you would end up writing code like this:
def dragEnterEvent(self, event): if event.mimeData().hasUrls(): event.acceptProposedAction() def dropEvent(self, event): if event->mimeData().hasUrls(): for url in event.mimeData().urls(): ...There are three approaches for storing custom data in a PySide.QtCore.QMimeData object:
On Windows, PySide.QtCore.QMimeData.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
PySide.QtGui.QClipboard PySide.QtGui.QDragEnterEvent PySide.QtGui.QDragMoveEvent PySide.QtGui.QDropEvent PySide.QtGui.QDrag QWindowsMime QMacPasteboardMime Drag and Drop
Constructs a new MIME data object with no data in it.
Removes all the MIME type and data entries in the object.
Return type: | object |
---|
Returns a color if the data stored in the object represents a color (MIME type application/x-color ); otherwise returns a null variant.
A PySide.QtCore.QVariant is used because PySide.QtCore.QMimeData belongs to the QtCore library, whereas PySide.QtGui.QColor belongs to QtGui . To convert the PySide.QtCore.QVariant to a PySide.QtGui.QColor , simply use qvariant_cast() . For example:
if event.mimeData().hasColor():
color = QColor(event.mimeData().colorData())
...
Parameters: | mimetype – unicode |
---|---|
Return type: | PySide.QtCore.QByteArray |
Returns the data stored in the object in the format described by the MIME type specified by mimeType .
See also
Return type: | list of strings |
---|
Returns a list of formats supported by the object. This is a list of MIME types for which the object can return suitable data. The formats in the list are in a priority order.
For the most common types of data, you can call the higher-level functions PySide.QtCore.QMimeData.hasText() , PySide.QtCore.QMimeData.hasHtml() , PySide.QtCore.QMimeData.hasUrls() , PySide.QtCore.QMimeData.hasImage() , and PySide.QtCore.QMimeData.hasColor() instead.
Return type: | PySide.QtCore.bool |
---|
Returns true if the object can return a color (MIME type application/x-color ); otherwise returns false.
Parameters: | mimetype – unicode |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if the object can return data for the MIME type specified by mimeType ; otherwise returns false.
For the most common types of data, you can call the higher-level functions PySide.QtCore.QMimeData.hasText() , PySide.QtCore.QMimeData.hasHtml() , PySide.QtCore.QMimeData.hasUrls() , PySide.QtCore.QMimeData.hasImage() , and PySide.QtCore.QMimeData.hasColor() instead.
Return type: | PySide.QtCore.bool |
---|
Returns true if the object can return HTML (MIME type text/html ); otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the object can return an image; otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the object can return plain text (MIME type text/plain ); otherwise returns false.
Return type: | PySide.QtCore.bool |
---|
Returns true if the object can return a list of urls; otherwise returns false.
URLs correspond to the MIME type text/uri-list .
Return type: | unicode |
---|
Returns a string if the data stored in the object is HTML (MIME type text/html ); otherwise returns an empty string.
Return type: | object |
---|
Returns a PySide.QtCore.QVariant storing a PySide.QtGui.QImage if the object can return an image; otherwise returns a null variant.
A PySide.QtCore.QVariant is used because PySide.QtCore.QMimeData belongs to the QtCore library, whereas PySide.QtGui.QImage belongs to QtGui . To convert the PySide.QtCore.QVariant to a PySide.QtGui.QImage , simply use qvariant_cast() . For example:
if event.mimeData().hasImage():
image = QImage(event.mimeData().imageData())
...
Parameters: | mimetype – unicode |
---|
Removes the data entry for mimeType in the object.
Parameters: |
|
---|---|
Return type: | object |
Parameters: | color – object |
---|
Sets the color data in the object to the given color .
Colors correspond to the MIME type application/x-color .
Parameters: |
|
---|
Sets the data associated with the MIME type given by mimeType to the specified data .
For the most common types of data, you can call the higher-level functions PySide.QtCore.QMimeData.setText() , PySide.QtCore.QMimeData.setHtml() , PySide.QtCore.QMimeData.setUrls() , PySide.QtCore.QMimeData.setImageData() , and PySide.QtCore.QMimeData.setColorData() instead.
Note that if you want to use a custom data type in an item view drag and drop operation, you must register it as a Qt meta type , using the Q_DECLARE_METATYPE() macro, and implement stream operators for it. The stream operators must then be registered with the qRegisterMetaTypeStreamOperators() function.
See also
PySide.QtCore.QMimeData.data() PySide.QtCore.QMimeData.hasFormat() QMetaType qRegisterMetaTypeStreamOperators()
Parameters: | html – unicode |
---|
Sets html as the HTML (MIME type text/html ) used to represent the data.
Parameters: | image – object |
---|
Sets the data in the object to the given image .
A PySide.QtCore.QVariant is used because PySide.QtCore.QMimeData belongs to the QtCore library, whereas PySide.QtGui.QImage belongs to QtGui . The conversion from PySide.QtGui.QImage to PySide.QtCore.QVariant is implicit. For example:
mimeData.setImageData(QImage("beautifulfjord.png"))
Parameters: | text – unicode |
---|
Sets text as the plain text (MIME type text/plain ) used to represent the data.
Parameters: | urls – |
---|
Return type: | unicode |
---|
Returns a plain text (MIME type text/plain ) representation of the data.
Return type: |
---|
Returns a list of URLs contained within the MIME data object.
URLs correspond to the MIME type text/uri-list .