Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

QMimeData Class Reference

The QMimeData class provides a container for data that records information about its MIME type. More...

#include <QMimeData>

Inherits QObject.

Writable Properties

Public Functions

Public Slots

Signals

Static Public Members

Protected Functions


Detailed Description

The QMimeData class provides a container for data that records information about its MIME type.

QMimeData is used to describe information that can be stored in the clipboard, and transferred via the drag and drop mechanism. 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.

QMimeData objects are usually created on the heap and supplied to QDrag or QClipboard objects. This is to enable Qt to manage the memory that they use.

The class provides a number of convenience functions to allow data in common formats to be stored and retrieved, and QMimeData objects can be queried to determine which kind of data they contain.

Textual data types are stored with setText() and setHtml(); they can be retrieved with text() and html(). Visual data types are stored with setColor(), setImage(), and setPixmap(); they can be retrieved with color(), image(), and pixmap(). The contents of the QMimeData object can be cleared with the clear() function.

Use the hasText() and hasHtml() functions to determine whether a given QMimeData object contains textual information; use hasColor(), hasImage(), and hasPixmap() to determine whether it contains standard visual types.

Custom data can be stored in a QMimeData object: Use the setData() function with a standard MIME description of the data, and a QByteArray containing the data itself. For example, although we could store an image or a pixmap using setImage() or setPixmap(), we can take a Portable Network Graphics (PNG) image from a QByteArray and explicitly store it in a QMimeData object using the following code:

    QByteArray pngImage;
    QMimeData *mimeData = new QMimeData;
    mimeData->setData("image/png", pngImage);

Usually, it is easier to rely on QMimeData's support for QImage and QPixmap when handling images.

See also QClipboard, QDrag, and and Drop.


Member Function Documentation

QMimeData::QMimeData ()

Constructs a new MIME data object.

QMimeData::~QMimeData ()

Destroys the MIME data object.

void QMimeData::clear ()

Removes all the MIME type and data entries in the object.

QColor QMimeData::color () const

Returns a color if the data stored in the object represents a color; otherwise returns a null color.

QByteArray QMimeData::data ( const QString & mimetype ) const

Returns the data stored in the object in the format described by the MIME type specified by mimetype.

QStringList QMimeData::formats () const   [virtual]

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.

bool QMimeData::hasColor () const

Returns true if the object can return a color otherwise returns false.

bool QMimeData::hasFormat ( const QString & mimetype ) const   [virtual]

Returns true if the object can return data for the MIME type specified by mimetype; otherwise returns false.

bool QMimeData::hasHtml () const

Returns true if the object can return HTML otherwise returns false.

bool QMimeData::hasImage () const

Returns true if the object can return a image otherwise returns false.

bool QMimeData::hasPixmap () const

Returns true if the object can return a pixmap otherwise returns false.

bool QMimeData::hasText () const

Returns true if the object can return text otherwise returns false.

bool QMimeData::hasUrls () const

Returns true if the object can return a list of urls otherwise returns false.

QString QMimeData::html () const

Returns a string if the data stored in the object is HTML; otherwise returns a null string.

QImage QMimeData::image () const

Returns a image if the data stored in the object is in the correct form; otherwise returns a null image.

QPixmap QMimeData::pixmap () const

Returns a pixmap if the data stored in the object is in the correct form; otherwise returns a null pixmap.

QVariant QMimeData::retrieveData ( const QString & mimetype, QVariant::Type type ) const   [virtual protected]

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. ###

void QMimeData::setColor ( const QColor & color )

Sets the data in the object to the given color.

void QMimeData::setData ( const QString & mimetype, const QByteArray & data )

Sets the data associated with the MIME type given by mimetype to the specified data.

void QMimeData::setHtml ( const QString & html )

Sets the data in the object to the HTML in the html string.

void QMimeData::setImage ( const QImage & image )

Sets the data in the object to the given image.

void QMimeData::setPixmap ( const QPixmap & pixmap )

Sets the data in the object to the given pixmap.

void QMimeData::setText ( const QString & text )

Sets text as the plain text used to represent the data.

void QMimeData::setUrls ( const QList<QUrl> & urls )

Sets the URLs stored in the MIME data object to those specified by urls.

QString QMimeData::text () const

Returns a plain text representation of the data.

QList<QUrl> QMimeData::urls () const

Returns a list of URLs contained within the MIME data object.


Copyright © 2004 Trolltech Trademarks
Qt 4.0.0-b1