Struct rute::auto::icon::Icon

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

Notice these docs are heavy WIP and not very relevent yet

A QIcon can generate smaller, larger, active, and disabled pixmaps from the set of pixmaps it is given. Such pixmaps are used by Qt widgets to show an icon representing a particular action.

The simplest use of QIcon is to create one from a QPixmap file or resource, and then use it, allowing Qt to work out all the required icon styles and sizes. For example:

To undo a QIcon, simply set a null icon in its place:

Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.

When you retrieve a pixmap using pixmap(QSize, Mode, State), and no pixmap for this given size, mode and state has been added with addFile() or addPixmap(), then QIcon will generate one on the fly. This pixmap generation happens in a QIconEngine. The default engine scales pixmaps down if required, but never up, and it uses the current style to calculate a disabled appearance. By using custom icon engines, you can customize every aspect of generated icons. With QIconEnginePlugin it is possible to register different icon engines for different file suffixes, making it possible for third parties to provide additional icon engines to those included with Qt.

Note: Since Qt 4.2, an icon engine that supports SVG is included.

Making Classes that Use QIcon

If you write your own widgets that have an option to set a small pixmap, consider allowing a QIcon to be set for that pixmap. The Qt class QToolButton is an example of such a widget.

Provide a method to set a QIcon, and when you draw the icon, choose whichever pixmap is appropriate for the current state of your widget. For example:

You might also make use of the Active mode, perhaps making your widget Active when the mouse is over the widget (see QWidget::enterEvent()),,) while the mouse is pressed pending the release that will activate the function, or when it is the currently selected item. If the widget can be toggled, the mode might be used to draw a different icon.

QIcon

Note: QIcon needs a QGuiApplication instance before the icon is created.

High DPI Icons

There are two ways that QIcon supports high DPI

icons: via addFile() and fromTheme().

addFile() is useful if you have your own custom directory structure and do not need to use the freedesktop.org Icon Theme Specification . Icons created via this approach use Qt’s “@nx” high DPI syntax

Using fromTheme() is necessary if you plan on following the Icon Theme Specification. To make QIcon use the high DPI version of an image, add an additional entry to the appropriate index.theme file:

Your icon theme directory would then look something like this:

See also: {fowler}{GUI Design Handbook: Iconic Label} {Icons Example}

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

Swaps icon other with this icon. This operation is very fast and never fails.

Returns a pixmap with the requested size, mode, and state, generating one if necessary. The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Overloads Returns a pixmap of size QSize( w, h). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Overloads Returns a pixmap of size QSize( extent, extent). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Returns a pixmap with the requested window size, mode, and state, generating one if necessary.

The pixmap can be smaller than the requested size. If window is on a high-dpi display the pixmap can be larger. In that case it will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Returns a pixmap with the requested size, mode, and state, generating one if necessary. The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Overloads Returns a pixmap of size QSize( w, h). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Overloads Returns a pixmap of size QSize( extent, extent). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Returns a pixmap with the requested window size, mode, and state, generating one if necessary.

The pixmap can be smaller than the requested size. If window is on a high-dpi display the pixmap can be larger. In that case it will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Returns a pixmap with the requested size, mode, and state, generating one if necessary. The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Overloads Returns a pixmap of size QSize( w, h). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Overloads Returns a pixmap of size QSize( extent, extent). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Returns a pixmap with the requested window size, mode, and state, generating one if necessary.

The pixmap can be smaller than the requested size. If window is on a high-dpi display the pixmap can be larger. In that case it will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Returns a pixmap with the requested size, mode, and state, generating one if necessary. The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Overloads Returns a pixmap of size QSize( w, h). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Overloads Returns a pixmap of size QSize( extent, extent). The pixmap might be smaller than requested, but never larger.

Setting the Qt::AA_UseHighDpiPixmaps application attribute enables this function to return pixmaps that are larger than the requested size. Such images will have a devicePixelRatio larger than 1.

Returns a pixmap with the requested window size, mode, and state, generating one if necessary.

The pixmap can be smaller than the requested size. If window is on a high-dpi display the pixmap can be larger. In that case it will have a devicePixelRatio larger than 1.

See also: [actual_size()] [paint()]

Returns the actual size of the icon for the requested size, mode, and state. The result might be smaller than requested, but never larger. The returned size is in device-independent pixels (This is relevant for high-dpi pixmaps.)

See also: [pixmap()] [paint()]

Returns the actual size of the icon for the requested window size, mode, and state.

The pixmap can be smaller than the requested size. The returned size is in device-independent pixels (This is relevant for high-dpi pixmaps.)

See also: [actual_size()] [pixmap()] [paint()]

Returns the actual size of the icon for the requested size, mode, and state. The result might be smaller than requested, but never larger. The returned size is in device-independent pixels (This is relevant for high-dpi pixmaps.)

See also: [pixmap()] [paint()]

Returns the actual size of the icon for the requested window size, mode, and state.

The pixmap can be smaller than the requested size. The returned size is in device-independent pixels (This is relevant for high-dpi pixmaps.)

See also: [actual_size()] [pixmap()] [paint()]

Returns the name used to create the icon, if available.

Depending on the way the icon was created, it may have an associated name. This is the case for icons created with fromTheme() or icons using a QIconEngine which supports the QIconEngine::IconNameHook.

See also: [from_theme()] [IconEngine]

Uses the painter to paint the icon with specified alignment, required mode, and state into the rectangle rect.

See also: [actual_size()] [pixmap()]

Mode mode, State state) const

Overloads Paints the icon into the rectangle QRect( x, y, w, h).

Uses the painter to paint the icon with specified alignment, required mode, and state into the rectangle rect.

See also: [actual_size()] [pixmap()]

Mode mode, State state) const

Overloads Paints the icon into the rectangle QRect( x, y, w, h).

Returns true if the icon is empty; otherwise returns false.

An icon is empty if it has neither a pixmap nor a filename.

Note: Even a non-null icon might not be able to create valid pixmaps, eg. if the file does not exist or cannot be read.

Returns a number that identifies the contents of this QIcon object. Distinct QIcon objects can have the same key if they refer to the same contents.

The cacheKey() will change when the icon is altered via addPixmap() or addFile().

Cache keys are mostly useful in conjunction with caching.

See also: Pixmap::cache_key

Adds pixmap to the icon, as a specialization for mode and state.

Custom icon engines are free to ignore additionally added pixmaps.

See also: [add_file()]

Adds an image from the file with the given fileName to the icon, as a specialization for size, mode and state. The file will be loaded on demand. Note: custom icon engines are free to ignore additionally added pixmaps.

If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.

The file name can refer to an actual file on disk or to one of the application’s embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application’s executable.

Use the QImageReader::supportedImageFormats() and QImageWriter::supportedImageFormats() functions to retrieve a complete list of the supported file formats.

If a high resolution version of the image exists (identified by the suffix @2x on the base name), it is automatically loaded and added with the device pixel ratio set to a value of 2. This can be disabled by setting the environment variable QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING (see QImageReader).

Note: When you add a non-empty filename to a QIcon, the icon becomes non-null, even if the file doesn’t exist or points to a corrupt file.

See also: [add_pixmap()] Pixmap::device_pixel_ratio

Indicate that this icon is a mask image(boolean isMask), and hence can potentially be modified based on where it’s displayed. See also: [is_mask()]

Returns true if this icon has been marked as a mask image. Certain platforms render mask icons differently (for example, menu icons on MacOS ).

See also: [set_is_mask()]

Returns the QIcon corresponding to name in the current icon theme.

The latest version of the freedesktop icon specification and naming specification can be obtained here:

To fetch an icon from the current icon theme:

Note: By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().

Note: Qt will make use of GTK’s icon-theme.cache if present to speed up the lookup. These caches can be generated using gtk-update-icon-cache: https://developer.gnome.org/gtk3/stable/gtk-update-icon-cache.html

Note: If an icon can’t be found in the current theme, then it will be searched in fallbackSearchPaths() as an unthemed icon.

See also: [theme_name()] [set_theme_name()] [theme_search_paths()] [fallback_search_paths()]

Overloads Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead.

If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:

Returns the QIcon corresponding to name in the current icon theme.

The latest version of the freedesktop icon specification and naming specification can be obtained here:

To fetch an icon from the current icon theme:

Note: By default, only X11 will support themed icons. In order to use themed icons on Mac and Windows, you will have to bundle a compliant theme in one of your themeSearchPaths() and set the appropriate themeName().

Note: Qt will make use of GTK’s icon-theme.cache if present to speed up the lookup. These caches can be generated using gtk-update-icon-cache: https://developer.gnome.org/gtk3/stable/gtk-update-icon-cache.html

Note: If an icon can’t be found in the current theme, then it will be searched in fallbackSearchPaths() as an unthemed icon.

See also: [theme_name()] [set_theme_name()] [theme_search_paths()] [fallback_search_paths()]

Overloads Returns the QIcon corresponding to name in the current icon theme. If no such icon is found in the current theme fallback is returned instead.

If you want to provide a guaranteed fallback for platforms that do not support theme icons, you can use the second argument:

Returns true if there is an icon available for name in the current icon theme, otherwise returns false.

See also: [theme_search_paths()] [from_theme()] [set_theme_name()]

Returns the name of the current icon theme.

On X11, the current icon theme depends on your desktop settings. On other platforms it is not set by default.

See also: [set_theme_name()] [theme_search_paths()] [from_theme()] [has_theme_icon()]

Sets the current icon theme to name.

The name should correspond to a directory name in the themeSearchPath() containing an index.theme file describing it’s contents.

See also: [theme_search_paths()] [theme_name()]

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.