QMimeData Class Reference |
Tester | Getter | Setter | MIME Types |
---|---|---|---|
hasText() | text() | setText() | text/plain |
hasHtml() | html() | setHtml() | text/html |
hasUrls() | urls() | setUrls() | text/uri-list |
hasImage() | imageData() | setImageData() | image/ * |
hasColor() | colorData() | setColorData() | application/x-color |
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.
Constructs a new MIME data object with no data in it.
Destroys the MIME data object.
Removes all the MIME type and data entries in the 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 QVariant is used because QMimeData belongs to the QtCore library, whereas QColor belongs to QtGui. To convert the QVariant to a QColor, simply use qvariant_cast(). For example:
if (event->mimeData()->hasColor()) { QColor color = qvariant_cast<QColor>(event->mimeData()->colorData()); ... }
See also hasColor(), setColorData(), and data().
Returns the data stored in the object in the format described by the MIME type specified by mimeType.
See also setData().
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 hasText(), hasHtml(), hasUrls(), hasImage(), and hasColor() instead.
See also hasFormat(), setData(), and data().
Returns true if the object can return a color (MIME type application/x-color); otherwise returns false.
See also setColorData(), colorData(), and hasFormat().
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 hasText(), hasHtml(), hasUrls(), hasImage(), and hasColor() instead.
See also formats(), setData(), and data().
Returns true if the object can return HTML (MIME type text/html); otherwise returns false.
See also setHtml(), html(), and hasFormat().
Returns true if the object can return an image; otherwise returns false.
See also setImageData(), imageData(), and hasFormat().
Returns true if the object can return plain text (MIME type text/plain); otherwise returns false.
See also setText(), text(), hasHtml(), and hasFormat().
Returns true if the object can return a list of urls; otherwise returns false.
URLs correspond to the MIME type text/uri-list.
See also setUrls(), urls(), and hasFormat().
Returns a string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string.
See also setHtml(), hasHtml(), and setData().
Returns a QVariant storing a QImage if the object can return an image; otherwise returns a null variant.
A QVariant is used because QMimeData belongs to the QtCore library, whereas QImage belongs to QtGui. To convert the QVariant to a QImage, simply use qvariant_cast(). For example:
if (event->mimeData()->hasImage()) { QImage image = qvariant_cast<QImage>(event->mimeData()->imageData()); ... }
See also setImageData() and hasImage().
Removes the data entry for mimeType in the object.
This function was introduced in Qt 4.4.
Returns a variant with the given type containing data for the MIME type specified by mimeType. If the object does not support the MIME type or variant type given, a null variant is returned instead.
This function is called by the general data() getter and by the convenience getters (text(), html(), urls(), imageData(), and colorData()). You can reimplement it if you want to store your data using a custom data structure (instead of a QByteArray, which is what setData() provides). You would then also need to reimplement hasFormat() and formats().
See also data().
Sets the color data in the object to the given color.
Colors correspond to the MIME type application/x-color.
See also colorData(), hasColor(), and setData().
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 setText(), setHtml(), setUrls(), setImageData(), and 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 data(), hasFormat(), QMetaType, and qRegisterMetaTypeStreamOperators().
Sets html as the HTML (MIME type text/html) used to represent the data.
See also html(), hasHtml(), setText(), and setData().
Sets the data in the object to the given image.
A QVariant is used because QMimeData belongs to the QtCore library, whereas QImage belongs to QtGui. The conversion from QImage to QVariant is implicit. For example:
mimeData->setImageData(QImage("beautifulfjord.png"));
See also imageData(), hasImage(), and setData().
Sets text as the plain text (MIME type text/plain) used to represent the data.
See also text(), hasText(), setHtml(), and setData().
Sets the URLs stored in the MIME data object to those specified by urls.
URLs correspond to the MIME type text/uri-list.
See also urls(), hasUrls(), and setData().
Returns a plain text (MIME type text/plain) representation of the data.
See also setText(), hasText(), html(), and data().
Returns a list of URLs contained within the MIME data object.
URLs correspond to the MIME type text/uri-list.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.4 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com