### Install qt-material-icons Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Install the library from PyPI. Optional bindings for PySide6, PySide2, or qtpy can be installed alongside. ```shell pip install qt-material-icons ``` ```shell pip install qt-material-icons PySide6 # PySide6 ``` ```shell pip install qt-material-icons PySide2 # PySide2 ``` ```shell pip install qt-material-icons qtpy # framework-agnostic wrapper ``` -------------------------------- ### Install qt-material-icons Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/README.md Install the library using pip. This is the primary method for adding the package to your project. ```shell pip install qt-material-icons ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/CONTRIBUTING.md Install the project and its development dependencies in editable mode. ```shell python -m pip install -e .[dev] ``` -------------------------------- ### Create and Customize QIcon with Material Icons Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/README.md Demonstrates how to create a QIcon object from a Material Icon name, set its color, and manage different colors or icons for various states like 'On'. ```python from PySide6 import QtGui from qt_material_icons import MaterialIcon # Create a QIcon object icon = MaterialIcon('search') # Set a color color = QtGui.QColor('red') icon.set_color(color) # Set a color for a state, for example when a button is checked icon.set_color(color, state=QtGui.QIcon.State.On) # Set a different icon for a state, for example when a button is checked toggle_icon = MaterialIcon('toggle_off') toggle_icon_on = MaterialIcon('toggle_on') toggle_icon.set_icon(toggle_icon_on, state=QtGui.QIcon.State.On) ``` -------------------------------- ### Create Virtual Environment Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/CONTRIBUTING.md Use this command to create a new virtual environment for the project. ```shell python -m venv venv ``` -------------------------------- ### Activate Virtual Environment (Linux/macOS) Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/CONTRIBUTING.md Activate the created virtual environment on Linux and macOS systems. ```shell source venv/bin/activate ``` -------------------------------- ### Activate Virtual Environment (Windows) Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/CONTRIBUTING.md Activate the created virtual environment on Windows systems. ```shell .\venv\Scripts\activate.bat ``` -------------------------------- ### Check Icon Availability Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Static method to verify if an icon/style/fill/size combination is bundled. Useful for graceful fallbacks. ```python from qt_material_icons import MaterialIcon MaterialIcon.resource_exists('name', style='outlined', fill=False, size=24) ``` -------------------------------- ### Compile Icons Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/CONTRIBUTING.md Run this script to update the Material Symbols resources. ```shell python compile_icons.py ``` -------------------------------- ### CLI - Extract Minimal Icon Subset Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt The `qtmaterialicons` command-line tool allows you to extract a minimal subset of icons, specified styles, and sizes into a target directory, compiling them into a self-contained Python resource module for smaller application distributions. ```APIDOC ## CLI — Extract a Minimal Icon Subset The `qtmaterialicons` command-line tool copies only the requested icons and the package skeleton into a target directory, then compiles them into a self-contained Python resource module. This keeps application distribution sizes small. ```shell # Extract home, search, settings in Outlined + Rounded styles at 20 and 24 px # Output goes into ./mypackage/qt_material_icons/ qtmaterialicons \ --names home search settings favorite download \ --styles outlined rounded \ --sizes 20 24 \ -o mypackage ``` The generated package can then be imported instead of the full library: ```python # In your application, replace: # from qt_material_icons import MaterialIcon # with: from mypackage.qt_material_icons import MaterialIcon icon = MaterialIcon('home') # works identically, but ships only 10 SVGs ``` ``` -------------------------------- ### Extract Specific Icons with CLI Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/README.md Use the `qtmaterialicons` CLI to extract specific icons, styles, sizes, and names into a custom package directory. This helps reduce the overall package size. ```shell qtmaterialicons -o mypackage --styles outlined rounded --sizes 20 24 --names home computer search favorite ``` -------------------------------- ### MaterialIcon(name, style, fill, size) Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Creates a Material Icon instance, which is a subclass of QIcon. It loads Material Symbol SVGs from the bundled Qt resource system and automatically inherits application palette colors. ```APIDOC ## MaterialIcon(name, style, fill, size) ### Description `MaterialIcon` is a `QIcon` subclass that loads a Material Symbol SVG from the bundled Qt resource system. The icon inherits the application palette colors automatically and can be used anywhere a `QIcon` is accepted. ### Parameters - **name** (string) - The name of the icon (e.g., 'search'). - **style** (enum, optional) - The style of the icon. Defaults to `MaterialIcon.OUTLINED`. Supported styles include `MaterialIcon.ROUNDED`, `MaterialIcon.SHARP`. - **fill** (boolean, optional) - Whether the icon should be filled. Defaults to `False`. - **size** (integer, optional) - The pixel size of the icon. Defaults to 20. ### Request Example ```python from PySide6 import QtWidgets from qt_material_icons import MaterialIcon app = QtWidgets.QApplication([]) # Default: outlined style, 20 px, not filled icon = MaterialIcon('search') # Rounded style, 24 px, filled variant icon_filled = MaterialIcon('home', style=MaterialIcon.ROUNDED, fill=True, size=24) # Sharp style at 48 px icon_sharp = MaterialIcon('settings', style=MaterialIcon.SHARP, size=48) # Use directly as a QIcon on any widget button = QtWidgets.QPushButton() button.setIcon(icon) button.setIconSize(__import__('PySide6').QtCore.QSize(48, 48)) print(repr(icon)) print(repr(icon_filled)) ``` ### Response Returns a `MaterialIcon` object, which is a subclass of `QIcon`. ``` -------------------------------- ### Version Release Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/CONTRIBUTING.md Use this command to version up your changes using python-semantic-release. ```shell semantic-release version ``` -------------------------------- ### Add qt-material-icons as a Dev Dependency Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/README.md Include qt-material-icons in your project's optional dependencies for development purposes, typically in `pyproject.toml`. ```toml # pyproject.toml [project.optional-dependencies] dev = ["qt-material-icons"] ``` -------------------------------- ### Create and Use MaterialIcon Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Instantiate MaterialIcon as a QIcon subclass. Icons automatically inherit application palette colors and can be used on any widget. The default is outlined style, 20px, not filled. ```python from PySide6 import QtWidgets from qt_material_icons import MaterialIcon app = QtWidgets.QApplication([]) # Default: outlined style, 20 px, not filled icon = MaterialIcon('search') # Rounded style, 24 px, filled variant icon_filled = MaterialIcon('home', style=MaterialIcon.ROUNDED, fill=True, size=24) # Sharp style at 48 px icon_sharp = MaterialIcon('settings', style=MaterialIcon.SHARP, size=48) # Use directly as a QIcon on any widget button = QtWidgets.QPushButton() button.setIcon(icon) button.setIconSize(QtWidgets.QStyle.standardIcon(button.style(), QtWidgets.QStyle.StandardPixmap.SP_DialogOkButton).availableSizes()[0] if False else __import__('PySide6').QtCore.QSize(48, 48)) print(repr(icon)) # MaterialIcon('search') print(repr(icon_filled)) # MaterialIcon('home') ``` -------------------------------- ### Check Icon Resource Existence Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Verify if an icon resource exists before attempting to construct it to prevent runtime errors. This is useful for validating icon names, styles, fill properties, and sizes. ```python from qt_material_icons import MaterialIcon combos = [ ('search', MaterialIcon.OUTLINED, False, 20), ('nonexistent', MaterialIcon.OUTLINED, False, 20), ('home', MaterialIcon.ROUNDED, True, 48), ] for name, style, fill, size in combos: exists = MaterialIcon.resource_exists(name, style, fill, size) print(f'{name!r:20s} {style.value:10s} fill={fill} {size}px → {exists}') ``` -------------------------------- ### Extract Icon Subset using CLI Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Use the qtmaterialicons CLI tool to copy only requested icons and package skeleton into a target directory, compiling them into a self-contained Python resource module for smaller distributions. ```shell qtmaterialicons \ --names home search settings favorite download \ --styles outlined rounded \ --sizes 20 24 \ -o mypackage ``` -------------------------------- ### MaterialIcon.resource_exists(name, style, fill, size) Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt A static method that checks if a specific icon, style, fill, and size combination is available in the bundled Qt resource system. This is useful for implementing fallback mechanisms. ```APIDOC ## MaterialIcon.resource_exists(name, style, fill, size) ### Description Static method that queries the Qt resource system to verify whether a particular icon/style/fill/size combination is bundled. Useful for graceful fallbacks when uncertain whether a specific icon name is available. ### Parameters - **name** (string) - The name of the icon to check. - **style** (enum, optional) - The style of the icon. Defaults to `MaterialIcon.OUTLINED`. - **fill** (boolean, optional) - Whether the icon is filled. Defaults to `False`. - **size** (integer, optional) - The pixel size of the icon. Defaults to 20. ### Request Example ```python from qt_material_icons import MaterialIcon # Check if the 'star' icon in default settings exists if MaterialIcon.resource_exists('star'): print("Star icon is available.") else: print("Star icon is not available.") # Check for a specific size and style if MaterialIcon.resource_exists('settings', style=MaterialIcon.ROUNDED, size=48): print("Rounded 48px settings icon is available.") ``` ### Response - **exists** (boolean) - `True` if the icon resource exists, `False` otherwise. ``` -------------------------------- ### Import Subset Package Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt After extracting a minimal icon subset using the CLI or API, import MaterialIcon from the generated package instead of the full library. ```python # In your application, replace: # from qt_material_icons import MaterialIcon # with: from mypackage.qt_material_icons import MaterialIcon icon = MaterialIcon('home') # works identically, but ships only 10 SVGs ``` -------------------------------- ### Import Localized Material Icons Source: https://github.com/beatreichenbach/qt-material-icons/blob/main/README.md Import the `MaterialIcon` class from your custom package after using the CLI to extract specific icons. ```python from mypackage.qt_material_icons import MaterialIcon ``` -------------------------------- ### Programmatic Icon Extraction Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Use the extract_icons_multi function to programmatically copy SVG files, write .qrc manifests, and compile them into resource modules via pyside6-rcc. ```python from qt_material_icons import MaterialIcon from qt_material_icons.extract import extract_icons_multi, extract_package # Step 1: copy __init__.py and _icon.py into the output package extract_package(output='dist/myapp') # Step 2: compile SVG resources for the icons you need extract_icons_multi( names=['home', 'search', 'settings', 'warning', 'error'], styles=[MaterialIcon.Style.OUTLINED, MaterialIcon.Style.ROUNDED], sizes=[20, 24], output='dist/myapp', ) # Produces: # dist/myapp/qt_material_icons/__init__.py # dist/myapp/qt_material_icons/_icon.py # dist/myapp/qt_material_icons/resources/icons_outlined_20.py # dist/myapp/qt_material_icons/resources/icons_outlined_24.py # dist/myapp/qt_material_icons/resources/icons_rounded_20.py ``` -------------------------------- ### Iterate and Access MaterialIcon Styles Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Enumerate all available icon styles and access them via class-level aliases. You can also construct styles from their string values, which is useful for configuration. ```python from qt_material_icons import MaterialIcon for style in MaterialIcon.Style: print(style, '→', style.value) # Access via alias assert MaterialIcon.OUTLINED is MaterialIcon.Style.OUTLINED assert MaterialIcon.ROUNDED is MaterialIcon.Style.ROUNDED assert MaterialIcon.SHARP is MaterialIcon.Style.SHARP # Construct from string value (useful when reading from config) style = MaterialIcon.Style('rounded') icon = MaterialIcon('mic', style=style, size=24) print(repr(icon)) ``` -------------------------------- ### Swap MaterialIcon for State Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Assign a different QIcon to a specific mode/state combination. Recommended for toggle buttons where the icon glyph changes. ```python from PySide6 import QtGui, QtWidgets from qt_material_icons import MaterialIcon app = QtWidgets.QApplication([]) # Base icon shown when button is unchecked (Off state) toggle_icon = MaterialIcon('toggle_off') # Icon shown when button is checked (On state) toggle_icon_on = MaterialIcon('toggle_on') toggle_icon.set_icon(toggle_icon_on, state=QtGui.QIcon.State.On) button = QtWidgets.QPushButton('Toggle') button.setCheckable(True) button.setIcon(toggle_icon) button.setIconSize(__import__('PySide6').QtCore.QSize(48, 48)) # Clicking the button now alternates between the two glyphs automatically ``` -------------------------------- ### Create and Tint Generic SVG Icons Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Use SVGIcon for custom SVG assets to apply Material Icon's theming behavior. You can tint icons with specific colors and define different colors for disabled states. ```python from PySide6 import QtGui, QtWidgets from qt_material_icons._icon import SVGIcon app = QtWidgets.QApplication([]) # Load any SVG — from disk or a Qt resource path icon = SVGIcon('/path/to/my_logo.svg') # Tint it to match a brand color icon.set_color(QtGui.QColor('#6200ee')) # Assign a lighter tint for the disabled state icon.set_color(QtGui.QColor('#bb86fc'), mode=QtGui.QIcon.Mode.Disabled) label = QtWidgets.QLabel() label.setPixmap(icon.pixmap(32)) # 32×32 px pixmap print(repr(icon)) ``` -------------------------------- ### Colorize a QPixmap with fill_pixmap Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Apply a specific color to all opaque pixels of a QPixmap using the SourceIn painter operation. This utility is useful for tinting monochrome icons or shapes outside the SVGIcon/MaterialIcon hierarchy. ```python from PySide6 import QtGui, QtWidgets from qt_material_icons._icon import fill_pixmap app = QtWidgets.QApplication([]) original = QtGui.QPixmap('/path/to/icon.png') tinted = fill_pixmap(original, QtGui.QColor('#43a047')) # green label = QtWidgets.QLabel() label.setPixmap(tinted) # 'tinted' is an independent copy; 'original' is unchanged ``` -------------------------------- ### SVGIcon Class Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt A generic SVG icon class that supports color tinting and state-based color changes. Use this for custom SVG assets to integrate them with Qt Material Icons' theming. ```APIDOC ## `SVGIcon(path)` — Generic SVG Icon with Color Support The base class for `MaterialIcon`. Accepts any file-system or Qt-resource SVG path and applies the same automatic palette-color and state-color features. Use this directly when you have custom SVG assets and want the same theming behaviour. ```python from PySide6 import QtGui, QtWidgets from qt_material_icons._icon import SVGIcon app = QtWidgets.QApplication([]) # Load any SVG — from disk or a Qt resource path icon = SVGIcon('/path/to/my_logo.svg') # Tint it to match a brand color icon.set_color(QtGui.QColor('#6200ee')) # Assign a lighter tint for the disabled state icon.set_color(QtGui.QColor('#bb86fc'), mode=QtGui.QIcon.Mode.Disabled) label = QtWidgets.QLabel() label.setPixmap(icon.pixmap(32)) # 32×32 px pixmap print(repr(icon)) # SVGIcon('my_logo.svg') ``` ``` -------------------------------- ### extract_icons_multi Function Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt The programmatic Python API equivalent to the CLI tool. It extracts specified icons, styles, and sizes, writes resource manifests, and compiles them into resource modules using `pyside6-rcc`. ```APIDOC ## `extract.extract_icons_multi(names, styles, sizes, output)` — Programmatic Extraction Python API equivalent of the CLI. Iterates over every requested `(style, size)` pair, extracts the SVG files, writes `.qrc` manifests, and compiles them into resource modules via `pyside6-rcc`. ```python from qt_material_icons import MaterialIcon from qt_material_icons.extract import extract_icons_multi, extract_package # Step 1: copy __init__.py and _icon.py into the output package extract_package(output='dist/myapp') # Step 2: compile SVG resources for the icons you need extract_icons_multi( names=['home', 'search', 'settings', 'warning', 'error'], styles=[MaterialIcon.Style.OUTLINED, MaterialIcon.Style.ROUNDED], sizes=[20, 24], output='dist/myapp', ) # Produces: # dist/myapp/qt_material_icons/__init__.py # dist/myapp/qt_material_icons/_icon.py # dist/myapp/qt_material_icons/resources/icons_outlined_20.py # dist/myapp/qt_material_icons/resources/icons_outlined_24.py # dist/myapp/qt_material_icons/resources/icons_rounded_20.py ``` ``` -------------------------------- ### fill_pixmap Utility Function Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt A standalone utility function to colorize a QPixmap. It fills opaque pixels with a specified QColor using the CompositionMode_SourceIn painter operation, useful for tinting monochrome icons or shapes. ```APIDOC ## `fill_pixmap(pixmap, color)` — Colorize a QPixmap Standalone utility that fills every opaque pixel of a `QPixmap` with a given `QColor` using the `CompositionMode_SourceIn` painter operation. Useful when you need a tinted copy of any monochrome icon or shape outside the `SVGIcon` / `MaterialIcon` hierarchy. ```python from PySide6 import QtGui, QtWidgets from qt_material_icons._icon import fill_pixmap app = QtWidgets.QApplication([]) original = QtGui.QPixmap('/path/to/icon.png') tinted = fill_pixmap(original, QtGui.QColor('#43a047')) # green label = QtWidgets.QLabel() label.setPixmap(tinted) # 'tinted' is an independent copy; 'original' is unchanged ``` ``` -------------------------------- ### Colorize MaterialIcon Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Override the default palette color for specific QIcon.Mode/State combinations. Calling with only a color changes the Normal/Off pixmap. ```python from PySide6 import QtGui, QtWidgets from qt_material_icons import MaterialIcon app = QtWidgets.QApplication([]) icon = MaterialIcon('favorite') # Solid red in the normal (enabled) state icon.set_color(QtGui.QColor('#e53935')) # Dimmed grey when the widget is disabled icon.set_color(QtGui.QColor('#9e9e9e'), mode=QtGui.QIcon.Mode.Disabled) # Different tint when a button is in the checked/On state icon.set_color(QtGui.QColor('#1e88e5'), state=QtGui.QIcon.State.On) button = QtWidgets.QPushButton() button.setCheckable(True) button.setIcon(icon) # The icon is red when unchecked, blue when checked, grey when disabled ``` -------------------------------- ### MaterialIcon.set_color(color, mode, state) Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Overrides the default palette color for a specific QIcon.Mode / QIcon.State combination. This allows for fine-grained control over the icon's color in different states (e.g., enabled, disabled, checked). ```APIDOC ## MaterialIcon.set_color(color, mode, state) ### Description Overrides the default palette color for a specific `QIcon.Mode` / `QIcon.State` combination. Calling this method with only a color changes the Normal/Off pixmap, which is the most common case. All Qt icon modes and states are supported. ### Parameters - **color** (QtGui.QColor) - The color to apply to the icon. - **mode** (QtGui.QIcon.Mode, optional) - The icon mode (e.g., `QtGui.QIcon.Mode.Normal`, `QtGui.QIcon.Mode.Disabled`). Defaults to `QtGui.QIcon.Mode.Normal`. - **state** (QtGui.QIcon.State, optional) - The icon state (e.g., `QtGui.QIcon.State.Off`, `QtGui.QIcon.State.On`). Defaults to `QtGui.QIcon.State.Off`. ### Request Example ```python from PySide6 import QtGui, QtWidgets from qt_material_icons import MaterialIcon app = QtWidgets.QApplication([]) icon = MaterialIcon('favorite') # Solid red in the normal (enabled) state icon.set_color(QtGui.QColor('#e53935')) # Dimmed grey when the widget is disabled icon.set_color(QtGui.QColor('#9e9e9e'), mode=QtGui.QIcon.Mode.Disabled) # Different tint when a button is in the checked/On state icon.set_color(QtGui.QColor('#1e88e5'), state=QtGui.QIcon.State.On) button = QtWidgets.QPushButton() button.setCheckable(True) button.setIcon(icon) # The icon is red when unchecked, blue when checked, grey when disabled ``` ### Response This method does not return a value; it modifies the icon's color properties in place. ``` -------------------------------- ### MaterialIcon.set_icon(icon, mode, state) Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Assigns a different MaterialIcon (or any QIcon) to a specific mode/state combination. This is useful for implementing toggle buttons where the icon glyph itself needs to change. ```APIDOC ## MaterialIcon.set_icon(icon, mode, state) ### Description Assigns a completely different `MaterialIcon` (or any `QIcon`) to a specific mode/state combination. This is the recommended way to implement toggle buttons where the icon glyph itself changes — for example, switching between `toggle_off` and `toggle_on`. ### Parameters - **icon** (QIcon) - The `QIcon` to assign for the specified mode and state. - **mode** (QtGui.QIcon.Mode, optional) - The icon mode (e.g., `QtGui.QIcon.Mode.Normal`, `QtGui.QIcon.Mode.Disabled`). Defaults to `QtGui.QIcon.Mode.Normal`. - **state** (QtGui.QIcon.State, optional) - The icon state (e.g., `QtGui.QIcon.State.Off`, `QtGui.QIcon.State.On`). Defaults to `QtGui.QIcon.State.Off`. ### Request Example ```python from PySide6 import QtGui, QtWidgets from qt_material_icons import MaterialIcon app = QtWidgets.QApplication([]) # Base icon shown when button is unchecked (Off state) toggle_icon = MaterialIcon('toggle_off') # Icon shown when button is checked (On state) toggle_icon_on = MaterialIcon('toggle_on') toggle_icon.set_icon(toggle_icon_on, state=QtGui.QIcon.State.On) button = QtWidgets.QPushButton('Toggle') button.setCheckable(True) button.setIcon(toggle_icon) button.setIconSize(__import__('PySide6').QtCore.QSize(48, 48)) # Clicking the button now alternates between the two glyphs automatically ``` ### Response This method does not return a value; it modifies the icon's assignment for the specified mode and state. ``` -------------------------------- ### MaterialIcon.Style Enum Source: https://context7.com/beatreichenbach/qt-material-icons/llms.txt Enumerates the available visual styles for Material Icons: OUTLINED, ROUNDED, and SHARP. These constants can be accessed directly or via the enum. ```APIDOC ## `MaterialIcon.Style` Enum — Available Icon Styles An `enum.Enum` that enumerates the three visual styles shipped with the Material Symbols set. Style constants are also available as class-level aliases (`MaterialIcon.OUTLINED`, `MaterialIcon.ROUNDED`, `MaterialIcon.SHARP`). ```python from qt_material_icons import MaterialIcon for style in MaterialIcon.Style: print(style, '→', style.value) # Style.OUTLINED → outlined # Style.ROUNDED → rounded # Style.SHARP → sharp # Access via alias assert MaterialIcon.OUTLINED is MaterialIcon.Style.OUTLINED assert MaterialIcon.ROUNDED is MaterialIcon.Style.ROUNDED assert MaterialIcon.SHARP is MaterialIcon.Style.SHARP # Construct from string value (useful when reading from config) style = MaterialIcon.Style('rounded') icon = MaterialIcon('mic', style=style, size=24) print(repr(icon)) # MaterialIcon('mic') ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.