6.0.0-rc4Source

QMimeData Class

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

Header#include <QMimeData>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes
InheritsQObject

List of all members, including inherited members

Public Functions

QMimeData()
~QMimeData()
QList<QUrl>urls() const
voidsetUrls(const QList<QUrl> &urls)
boolhasUrls() const
QStringtext() const
voidsetText(const QString &text)
boolhasText() const
QStringhtml() const
voidsetHtml(const QString &html)
boolhasHtml() const
QVariantimageData() const
voidsetImageData(const QVariant &image)
boolhasImage() const
QVariantcolorData() const
voidsetColorData(const QVariant &color)
boolhasColor() const
QByteArraydata(const QString &mimeType) const
voidsetData(const QString &mimeType, const QByteArray &data)
voidremoveFormat(const QString &mimeType)
virtual boolhasFormat(const QString &mimeType) const
virtual QStringListformats() const
voidclear()

Protected Functions

virtual QVariantretrieveData(const QString &mimeType, QMetaType preferredType) const

Detailed Description

A QMimeData holds data in several formats, each named by a MIME type, as used by the clipboard, drag and drop and QAbstractItemModel::mimeData(). Convenience functions handle plain text (text/plain), HTML (text/html) and URL lists (text/uri-list):

auto *data = new QMimeData;
data->setText(u"hello"_s);
data->setData(u"application/x-mine"_s, payload);

See also QAbstractItemModel::mimeData().

Differences from Qt

Images and colors are stored as QVariant values under the formats application/x-qt-image and application/x-color; Nt has no conversion of images to and from encoded image formats.

Member Function Documentation

QMimeData::QMimeData()

Constructs an empty QMimeData.

[override] QMimeData::~QMimeData()

Destroys the QMimeData.

void QMimeData::clear()

Removes all formats.

QVariant QMimeData::colorData() const

Returns the color stored with setColorData(), or an invalid QVariant.

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

Returns the data of the format mimeType, or an empty byte array.

See also setData() and hasFormat().

[virtual] QStringList QMimeData::formats() const

Returns the formats the object holds, in the order they were set.

bool QMimeData::hasColor() const

Returns true if a color is stored; otherwise returns false.

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

Returns true if the object has the format mimeType; otherwise returns false.

bool QMimeData::hasHtml() const

Returns true if the object has the text/html format; otherwise returns false.

bool QMimeData::hasImage() const

Returns true if an image is stored; otherwise returns false.

bool QMimeData::hasText() const

Returns true if the object has the text/plain format; otherwise returns false. A URL list also counts as text.

bool QMimeData::hasUrls() const

Returns true if the object has the text/uri-list format; otherwise returns false.

QString QMimeData::html() const

Returns the HTML of the text/html format, or an empty string.

QVariant QMimeData::imageData() const

Returns the image stored with setImageData(), or an invalid QVariant.

void QMimeData::removeFormat(const QString &mimeType)

Removes the format mimeType.

[virtual, protected] QVariant QMimeData::retrieveData(const QString &mimeType, QMetaType preferredType) const

Returns the data of the format mimeType. preferredType is a hint for the type of the result. Reimplement it to provide data on demand.

void QMimeData::setColorData(const QVariant &color)

Stores the color color.

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

Sets the data of the format mimeType to data, replacing any earlier data of that format.

void QMimeData::setHtml(const QString &html)

Sets the text/html format to html, encoded as UTF-8.

void QMimeData::setImageData(const QVariant &image)

Stores the image image.

void QMimeData::setText(const QString &text)

Sets the text/plain format to text, encoded as UTF-8.

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

Sets the text/uri-list format to urls, one URL per line.

QString QMimeData::text() const

Returns the plain text of the text/plain format, or an empty string.

QList<QUrl> QMimeData::urls() const

Returns the URLs of the text/uri-list format. Lines starting with # are comments.

See also setUrls() and hasUrls().