Struct rute::auto::mime_data::MimeData

source ·
pub struct MimeData<'a> { /* private fields */ }
Expand description

Notice these docs are heavy WIP and not very relevent yet

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 using new and supplied to QDrag or QClipboard objects. This is to enable Qt to manage the memory that they use.

A single QMimeData object can store the same data using several different formats at the same time. The formats() function returns a list of the available formats in order of preference. The data() function returns the raw data associated with a MIME type, and setData() allows you to set the data for a MIME type.

For the most common MIME types, QMimeData provides convenience functions to access the data:

  • 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:

There are three approaches for storing custom data in a QMimeData object:

  • Custom data can be stored directly in a QMimeData object as a QByteArray using setData(). For example:
  • We can subclass QMimeData and reimplement hasFormat(), formats(), and retrieveData().
  • If the drag and drop operation occurs within a single application, we can subclass QMimeData and add extra data in it, and use a qobject_cast() in the receiver’s drop event handler. For example:

Platform-Specific MIME Types

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:

The following are examples of custom MIME types:

The value declaration of each format describes the way in which the data is encoded.

In some cases (e.g. dropping multiple email attachments), multiple data values are available. They can be accessed by adding an index value:

On Windows, the MIME format does not always map directly to the clipboard formats. Qt provides QWinMime to map clipboard formats to open-standard MIME formats. Similarly, the QMacPasteboardMime maps MIME to Mac flavors.

See also: [Clipboard] DragEnterEvent DragMoveEvent DropEvent [Drag] [MacPasteboardMime] {Drag and Drop}

Licence

The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.

Implementations

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

URLs correspond to the MIME type text/uri-list.

See also: [has_urls()] [data()]

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

URLs correspond to the MIME type text/uri-list.

Since Qt 5.0, setUrls also exports the urls as plain text, if setText was not called before, to make it possible to drop them into any lineedit and text editor.

See also: [has_urls()] [set_data()]

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: [set_urls()] [urls()] [has_format()]

Returns a plain text (MIME type text/plain) representation of the data.

See also: [has_text()] [html()] [data()]

Sets text as the plain text (MIME type text/plain) used to represent the data.

See also: [has_text()] [set_html()] [set_data()]

Returns true if the object can return plain text (MIME type text/plain); otherwise returns false.

See also: [set_text()] [text()] [has_html()] [has_format()]

Returns a string if the data stored in the object is HTML (MIME type text/html); otherwise returns an empty string.

See also: [has_html()] [set_data()]

Sets html as the HTML (MIME type text/html) used to represent the data.

See also: [has_html()] [set_text()] [set_data()]

Returns true if the object can return HTML (MIME type text/html); otherwise returns false.

See also: [set_html()] [html()] [has_format()]

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 Qt Core module, whereas QImage belongs to Qt GUI. To convert the QVariant to a QImage, simply use qvariant_cast(). For example:

See also: [has_image()]

Sets the data in the object to the given image.

A QVariant is used because QMimeData belongs to the Qt Core module, whereas QImage belongs to Qt GUI. The conversion from QImage to QVariant is implicit. For example:

See also: [has_image()] [set_data()]

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

See also: [set_image_data()] [image_data()] [has_format()]

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 Qt Core module, whereas QColor belongs to Qt GUI. To convert the QVariant to a QColor, simply use qvariant_cast(). For example:

See also: [has_color()] [set_color_data()] [data()]

Sets the color data in the object to the given color.

Colors correspond to the MIME type application/x-color.

See also: [has_color()] [set_data()]

Returns true if the object can return a color (MIME type application/x-color); otherwise returns false.

See also: [set_color_data()] [color_data()] [has_format()]

Removes the data entry for mimeType in the object.

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()] [set_data()] [data()]

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: [has_format()] [set_data()] [data()]

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

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.