QMimeData Class
The QMimeData class provides a container for data that records information about its MIME type. More…
| Header | #include <QMimeData> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Core) |
| Module | Nt Core C++ Classes |
| Inherits | QObject |
List of all members, including inherited members
Public Functions
| QMimeData() | |
| ~QMimeData() | |
| QList<QUrl> | urls() const |
| void | setUrls(const QList<QUrl> &urls) |
| bool | hasUrls() const |
| QString | text() const |
| void | setText(const QString &text) |
| bool | hasText() const |
| QString | html() const |
| void | setHtml(const QString &html) |
| bool | hasHtml() const |
| QVariant | imageData() const |
| void | setImageData(const QVariant &image) |
| bool | hasImage() const |
| QVariant | colorData() const |
| void | setColorData(const QVariant &color) |
| bool | hasColor() const |
| QByteArray | data(const QString &mimeType) const |
| void | setData(const QString &mimeType, const QByteArray &data) |
| void | removeFormat(const QString &mimeType) |
| virtual bool | hasFormat(const QString &mimeType) const |
| virtual QStringList | formats() const |
| void | clear() |
Protected Functions
| virtual QVariant | retrieveData(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.
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().
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.
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.
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.