DCStyleIcons Class
The DCStyleIcons class provides a mechanism to extract and manage icons from specialized XML/FastInfoset resource files. More...
| Header: | #include <DCStyleIcons> |
| Inherits: | QObject |
Properties
- aspectRatioMode : Qt::AspectRatioMode
- resizable : bool
Public Functions
| DCStyleIcons(const QString &fileName) | |
| virtual | ~DCStyleIcons() override |
| Qt::AspectRatioMode | aspectRatioMode() const |
| QIcon | icon(const QString &iconName, const QString &themeName = QString()) const |
| QStringList | iconNames() const |
| bool | isResizable() const |
| void | setAspectRatioMode(Qt::AspectRatioMode mode) |
| void | setResizable(bool resizable) |
Detailed Description
This class is used to load and manage icons generated by the DCMake.exe utility. These resources are typically created by exporting design assets from Figma or Adobe XD and converting them into an optimized XML/FastInfoset format (usually with a .design extension) for use within Qt-based applications.
DCStyleIcons allows for theme-aware icon retrieval, provides access to the full list of available icon identifiers, and manages how icons are scaled via aspect ratio settings.
Component Structure
To ensure proper integration, each icon in the Figma or Adobe XD file must be defined as a Component. These components can include various States and Variants to support standard Qt icon functionality:
- QIcon::State: Component variants can map to On and Off states.
- QIcon::Mode: Different visual representations can be provided for Normal, Disabled, Active, and Selected modes.
When used in a Qt application, these components are rendered via a custom QIconEngine. This engine ensures that the icon scales dynamically, honoring the layout and constraint settings defined within the original Figma or Adobe XD design.
Resource Generation
To generate the .design file required by this class from a Figma source, use the following command:
DCMake.exe -i "ui_assets.fig" -o "ui_assets.design" -c -f online
Usage Example
The following example demonstrates how to load a resource file and retrieve a specific icon for a button:
DCStyleIcons styleIcons(":/resources/ui_assets.design"); // Retrieve a standard icon QIcon homeIcon = styleIcons.icon("home_action"); myButton->setIcon(homeIcon); // Retrieve a theme-specific version of an icon QIcon darkSearchIcon = styleIcons.icon("search", "dark_theme");
See also QIcon and QIconEngine.
Property Documentation
aspectRatioMode : Qt::AspectRatioMode
This property holds how the icon respects its aspect ratio when being resized.
This property only affects the rendering if the resizable property is set to true. It determines how the dynamic layout engine fits the icon's content into the requested geometry (e.g., Qt::KeepAspectRatio or Qt::IgnoreAspectRatio).
If resizable is false, this property is ignored in favor of a direct QPainter transformation.
The default value is Qt::KeepAspectRatio.
Access functions:
| Qt::AspectRatioMode | aspectRatioMode() const |
| void | setAspectRatioMode(Qt::AspectRatioMode mode) |
See also resizable and Qt::AspectRatioMode.
resizable : bool
This property holds whether the dynamic layout engine is used for icon resizing.
When this property is true (the default), the class employs an internal dynamic layout engine. This engine ensures icons are redrawn optimally for the requested size while strictly respecting the aspectRatioMode.
When set to false, the dynamic engine is bypassed. The icon is simply scaled to the target size using a standard QPainter transformation, and the aspectRatioMode property is ignored.
Access functions:
| bool | isResizable() const |
| void | setResizable(bool resizable) |
See also aspectRatioMode.
Member Function Documentation
DCStyleIcons::DCStyleIcons(const QString &fileName)
Constructs a DCStyleIcons object and loads icon data from the specified fileName. The file must be a valid XML resource produced by the DCMake utility.
[override virtual noexcept] DCStyleIcons::~DCStyleIcons()
Destroys the DCStyleIcons object and releases all allocated resources.
Qt::AspectRatioMode DCStyleIcons::aspectRatioMode() const
Returns the current aspect ratio mode used when rendering or processing icons.
Note: Getter function for property aspectRatioMode.
See also setAspectRatioMode().
QIcon DCStyleIcons::icon(const QString &iconName, const QString &themeName = QString()) const
Returns a QIcon for the given iconName. If themeName is provided, the class attempts to retrieve the version of the icon specific to that theme. Returns a null icon if the name is not found.
QStringList DCStyleIcons::iconNames() const
Returns a list of all icon names available in the loaded resource file.
bool DCStyleIcons::isResizable() const
Returns true if the dynamic layout engine is enabled for icon resizing.
Note: Getter function for property resizable.
void DCStyleIcons::setAspectRatioMode(Qt::AspectRatioMode mode)
Sets the aspect ratio mode to be used for the icons managed by this class.
Note: Setter function for property aspectRatioMode.
See also aspectRatioMode().
void DCStyleIcons::setResizable(bool resizable)
Sets whether to use the dynamic layout engine to resizable.
Note: Setter function for property resizable.
See also isResizable().