fxicons
Icon management functionality for fxgui.
This module provides utilities for loading, caching, and manipulating icons from multiple icon libraries including Material Icons, Font Awesome, Simple Icons, and custom DCC (Digital Content Creation) icons.
The module supports
- Multiple icon libraries with configurable defaults
- Icon color customization
- Automatic caching using LRU cache for performance
- Icon superposition for composite icons
- Pixmap and QIcon conversion utilities
Functions:
| Name | Description |
|---|---|
get_icon |
Get a QIcon from an icon library. |
get_pixmap |
Get a QPixmap from an icon library. |
get_icon_path |
Get the file path of an icon. |
clear_icon_cache |
Clear the icon LRU cache. |
set_default_icon_library |
Set the default icon library. |
set_icon_defaults |
Configure default icon parameters. |
add_library |
Add a custom icon library. |
Examples:
Basic icon usage:
>>> from fxgui.fxicons import get_icon
>>> icon = get_icon("home")
>>> colored_icon = get_icon("settings", color="#FF5722")
Using different libraries:
>>> fa_icon = get_icon("lemon", library="fontawesome")
>>> dcc_icon = get_icon("houdini", library="dcc")
add_library
Add a new icon library to the available libraries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the library. |
required |
|
str
|
The pattern to use for the library. Valid placeholders are:
- |
required |
|
Dict
|
The default values for the library. |
required |
|
Optional[Path]
|
The root path for the library. Defaults to
|
None
|
Examples:
change_pixmap_color
Change the color of a pixmap.
Uses QPainter with composition mode for efficient colorization while preserving the original alpha channel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QPixmap
|
The pixmap to change the color of. |
required |
|
str
|
The color to apply. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
QPixmap |
QPixmap
|
The pixmap with the new color applied. |
clear_icon_cache
convert_icon_to_pixmap
convert_icon_to_pixmap(
icon: QIcon, desired_size: Optional[QSize] = None
) -> Optional[QPixmap]
Converts a QIcon to a QPixmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QIcon
|
The QIcon to convert. |
required |
|
Optional[QSize]
|
The desired size for the pixmap (QSize). If |
None
|
Returns:
| Type | Description |
|---|---|
Optional[QPixmap]
|
A QPixmap or |
Examples:
Let the size be decided
Choose a size
get_available_icons_in_library
get_available_icons_in_library(library: str) -> List[str]
Get all available icon names in the specified library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the library. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: The available icon names in the library. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the library does not exist. |
FileNotFoundError
|
If no icons are found in the library. |
Examples:
get_available_libraries
get_icon
get_icon(
icon_name: str,
width: Optional[int] = None,
height: Optional[int] = None,
color: Optional[str] = None,
library: Optional[str] = None,
style: Optional[str] = None,
extension: Optional[str] = None,
) -> QIcon
Get a QIcon of the specified icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the icon. |
required |
|
Optional[int]
|
The width of the pixmap. Defaults to |
None
|
|
Optional[int]
|
The height of the pixmap. Defaults to |
None
|
|
Optional[str]
|
The color to convert the pixmap to. Defaults to |
None
|
|
Optional[str]
|
The library of the icon. Defaults to |
None
|
|
Optional[str]
|
The style of the icon. Defaults to |
None
|
|
Optional[str]
|
The extension of the icon. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
QIcon |
QIcon
|
The QIcon of the icon. |
Examples:
get_icon_color
Get the current default icon color.
Returns the icon color from the current theme. This is the canonical source for icon color and is synchronized with the theme.
Returns:
| Type | Description |
|---|---|
str
|
The current default icon color as a hex string. |
Examples:
get_icon_path
get_icon_path(
icon_name: str,
library: Optional[str] = None,
style: Optional[str] = None,
extension: Optional[str] = None,
) -> str
Get the path of the specified icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the icon. |
required |
|
Optional[str]
|
The library of the icon. Defaults to |
None
|
|
Optional[str]
|
The style of the icon. Defaults to |
None
|
|
Optional[str]
|
The extension of the icon. Defaults to |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If verify is |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The path of the icon. |
Examples:
get_pixmap
get_pixmap(
icon_name: str,
width: Optional[int] = None,
height: Optional[int] = None,
color: Optional[str] = None,
library: Optional[str] = None,
style: Optional[str] = None,
extension: Optional[str] = None,
) -> QPixmap
Get a QPixmap of the specified icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The name of the icon. |
required |
|
Optional[int]
|
The width of the pixmap. Defaults to |
None
|
|
Optional[int]
|
The height of the pixmap. Defaults to |
None
|
|
Optional[str]
|
The color to convert the pixmap to. Defaults to |
None
|
|
Optional[str]
|
The library of the icon. Defaults to |
None
|
|
Optional[str]
|
The style of the icon. Defaults to |
None
|
|
Optional[str]
|
The extension of the icon. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
QPixmap |
QPixmap
|
The QPixmap of the icon. |
Examples:
has_transparency
has_transparency(mask: QBitmap) -> bool
Check if a mask has any transparency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QBitmap
|
The mask to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
refresh_all_icons
Refresh icons on all registered widgets.
This is automatically called by sync_colors_with_theme(), but can
be called manually if needed.
set_default_icon_library
set_default_icon_library(library: str)
set_icon
Set an icon on a widget and register it for automatic theme updates.
This is the recommended way to set icons on widgets. The icon will automatically refresh when the theme changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
The widget to set the icon on (QAction, QPushButton, etc.). |
required | |
|
str
|
The name of the icon. |
required |
|
Optional parameters passed to get_icon (width, height, color, library, style, extension). |
{}
|
Returns:
| Type | Description |
|---|---|
QIcon
|
The QIcon that was set on the widget. |
Examples:
set_icon_defaults
Set the default values for the icons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Optional[str]
|
The library to apply the defaults to. If set to |
None
|
|
Any
|
The default values to set. |
{}
|
Examples:
superpose_icons
superpose_icons(*icons: QIcon) -> QIcon
Superpose multiple icons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
QIcon
|
Icons to superpose. Add the icons in the order you want them to be superposed, from background to foreground. |
()
|
Returns:
| Name | Type | Description |
|---|---|---|
QIcon |
QIcon
|
The QIcon of the superposed icons. |
Notes
The size of the resulting icon is the size of the first icon.
Examples:
sync_colors_with_theme
Synchronize icon colors with the current theme from fxstyle.
This function reads the icon color from the current theme's JSONC configuration and updates all icon library defaults accordingly. It also clears the icon cache and refreshes all registered widget icons.
This is automatically called by fxstyle.apply_theme(), but can
also be called manually when needed.
Examples: