### Clone, Install, and Run qt-material Examples Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Provides instructions for cloning the qt-material repository, installing it, and running the full features example to test themes and create new ones. ```shell git clone https://github.com/UN-GCPDS/qt-material.git cd qt-material python setup.py install cd examples/full_features python main.py --pyside6 ``` -------------------------------- ### Install qt-material Package Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md This code snippet shows the command to install the qt-material package using pip. It's a prerequisite for using the stylesheet in your PySide or PyQt applications. ```ipython3 pip install qt-material ``` -------------------------------- ### Create Custom Theme XML Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md An example of an Android XML color resource file used to define custom Material Design themes. This file should be saved with a '.xml' extension and can then be applied using `apply_stylesheet`. ```xml #00e5ff #6effff #f5f5f5 #ffffff #e6e6e6 #000000 #000000 ``` -------------------------------- ### Configure UI Density Scale with PySide6 Source: https://context7.com/un-gcpds/qt-material/llms.txt This example shows how to apply a specific density scale to a Qt application using `qt_material.apply_stylesheet`. The `density_scale` parameter in the `extra` dictionary can be set from -3 (most compact) to +3 (most spacious). ```python from PySide6 import QtWidgets from qt_material import apply_stylesheet import sys app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # Apply compact density for information-dense interfaces extra_compact = { 'density_scale': '-2', # Range: -3 to +3 } apply_stylesheet(app, theme='dark_teal.xml', extra=extra_compact) # Create sample UI to see density changes central_widget = QtWidgets.QWidget() layout = QtWidgets.QVBoxLayout(central_widget) for i in range(5): button = QtWidgets.QPushButton(f'Button {i+1}') layout.addWidget(button) checkbox = QtWidgets.QCheckBox('Compact Layout') layout.addWidget(checkbox) window.setCentralWidget(central_widget) window.show() app.exec() ``` -------------------------------- ### Customize QMenu Appearance with PySide6 Source: https://context7.com/un-gcpds/qt-material/llms.txt This example shows how to customize the appearance of QMenu widgets using the `extra` dictionary in `apply_stylesheet`. It allows setting properties like `height` and `padding` for menus, potentially differing across platforms. ```python from PySide6 import QtWidgets from qt_material import apply_stylesheet import sys app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # Configure QMenu appearance extra = { 'QMenu': { 'height': 40, 'padding': '10px 20px 10px 20px', # top, right, bottom, left } } apply_stylesheet(app, theme='light_blue.xml', invert_secondary=True, extra=extra) # Create menu bar with custom styling menubar = window.menuBar() file_menu = menubar.addMenu('File') file_menu.addAction('New') file_menu.addAction('Open') file_menu.addAction('Save') file_menu.addSeparator() file_menu.addAction('Exit') edit_menu = menubar.addMenu('Edit') edit_menu.addAction('Cut') edit_menu.addAction('Copy') edit_menu.addAction('Paste') window.show() app.exec() ``` -------------------------------- ### Get Available Qt-Material Theme Names (Python) Source: https://context7.com/un-gcpds/qt-material/llms.txt Retrieves a list of all built-in theme names available within the qt-material library. This includes various dark and light Material Design color palettes. The function can be used to dynamically select and apply themes. ```python from qt_material import list_themes # Get all available themes available_themes = list_themes() print(available_themes) # Output: ['dark_amber.xml', 'dark_blue.xml', 'dark_cyan.xml', # 'dark_lightgreen.xml', 'dark_pink.xml', 'dark_purple.xml', # 'dark_red.xml', 'dark_teal.xml', 'dark_yellow.xml', # 'light_amber.xml', 'light_blue.xml', 'light_cyan.xml', # 'light_cyan_500.xml', 'light_lightgreen.xml', 'light_pink.xml', # 'light_purple.xml', 'light_red.xml', 'light_teal.xml', # 'light_yellow.xml'] # Apply a theme from the list from PySide6 import QtWidgets from qt_material import apply_stylesheet app = QtWidgets.QApplication([]) window = QtWidgets.QMainWindow() for theme in available_themes: if 'dark_purple' in theme: apply_stylesheet(app, theme=theme) break window.show() app.exec() ``` -------------------------------- ### Create New Themes Using Runtime Interface Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Explains how to use a simple interface to modify themes at runtime, creating a new theme file (e.g., my_theme.xml) in the main directory. ```python class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.show_dock_theme(self.main) ``` -------------------------------- ### Basic Qt App Initialization (Python) Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Initializes a basic Qt application window with a QCheckBox. This demonstrates fundamental QtWidgets usage. It requires the PyQt5 library. ```python from PyQt5 import QtWidgets window = QtWidgets.QMainWindow() checkbox = QtWidgets.QCheckBox(window) checkbox.text = 'CheckBox' window.show() app.exec() ``` -------------------------------- ### Create New Themes at Runtime with QtMaterial in Python Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.ipynb This Python code illustrates how to use a simple interface to modify themes at runtime, facilitating the creation of new themes. The show_dock_theme method displays a dockable widget that allows for live theme adjustments. New themes are saved as '.xml' files in the main directory. ```python from qt_material import QtStyleTools from PySide6 import QtWidgets from PySide6.QtUiTools import QUiLoader from PySide6.QtWidgets import QMainWindow class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.show_dock_theme(self.main) ``` -------------------------------- ### Create New Themes in Runtime Source: https://github.com/un-gcpds/qt-material/blob/master/README.md This Python code demonstrates how to create new themes dynamically at runtime using the `show_dock_theme` method, which provides an interface for modifying themes. The generated theme file, e.g., `my_theme.xml`, is saved in the main directory. ```python from qt_material import QtStyleTools from PySide6.QtWidgets import QMainWindow from PySide6.QtUiTools import QUiLoader class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.show_dock_theme(self.main) ``` -------------------------------- ### Apply Stylesheet in PySide/PyQt Application Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Demonstrates how to import necessary modules from PySide6 (or PySide2/PyQt5/PyQt6) and apply a Material Design stylesheet to a QApplication. It sets up a main window and applies a 'dark_teal.xml' theme. ```python import sys from PySide6 import QtWidgets # from PySide2 import QtWidgets # from PyQt5 import QtWidgets from qt_material import apply_stylesheet # create the application and the main window app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # setup stylesheet apply_stylesheet(app, theme='dark_teal.xml') # run window.show() app.exec_() ``` -------------------------------- ### Runtime Theme Switching with QtStyleTools Source: https://context7.com/un-gcpds/qt-material/llms.txt Demonstrates how to use the QtStyleTools mixin to enable runtime theme switching, add theme selection menus, and create theme customization interfaces. This requires inheriting from QMainWindow and QtStyleTools. ```python from PySide6.QtWidgets import QApplication, QMainWindow from PySide6.QtUiTools import QUiLoader from qt_material import QtStyleTools, apply_stylesheet class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) # Set initial theme apply_stylesheet(self.main, 'dark_teal.xml') # Add theme selection menu (requires menuStyles in UI) self.add_menu_theme(self.main, self.main.menuStyles) # Add density scale menu (requires menuDensity in UI) extra = {'density_scale': '0'} self.set_extra(extra) self.add_menu_density(self.main, self.main.menuDensity) # Show theme customization dock (creates color pickers) self.show_dock_theme(self.main) # Manually switch themes on button clicks self.main.pushButton.clicked.connect( lambda: self.apply_stylesheet(self.main, 'dark_purple.xml') ) self.main.pushButton_2.clicked.connect( lambda: self.apply_stylesheet(self.main, 'light_blue.xml', invert_secondary=True) ) if __name__ == "__main__": app = QApplication([]) frame = RuntimeStylesheets() frame.main.show() app.exec() ``` -------------------------------- ### Change Theme at Runtime with QtStyleTools Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Shows how to inherit from qt_material.QtStyleTools and QMainWindow to enable changing application themes dynamically using the apply_stylesheet method. ```python class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.apply_stylesheet(self.main, 'dark_teal.xml') # self.apply_stylesheet(self.main, 'light_red.xml') # self.apply_stylesheet(self.main, 'light_blue.xml') ``` -------------------------------- ### Integrate Stylesheet Menu for Theme Switching Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Demonstrates how to add a custom stylesheet menu to a Qt application, allowing users to switch between available themes at runtime by inheriting from QtStyleTools. ```python class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.add_menu_theme(self.main, self.main.menuStyles) ``` -------------------------------- ### Python: Initialize Qt Application Window and CheckBox Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/index.md Initializes a Qt application's main window and a checkbox widget. Sets the text for the checkbox and displays the main window. This code requires the QtWidgets module from a Qt binding for Python. ```python window = QtWidgets.QMainWindow() checkbox = QtWidgets.QCheckBox(window) checkbox.text = 'CheckBox' window.show() app.exec() ``` -------------------------------- ### Apply Light Theme with Inverted Secondary Color Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md This Python code demonstrates how to apply a light theme and uses the `invert_secondary=True` argument. This is typically needed for light themes to ensure proper color contrast and appearance. ```python apply_stylesheet(app, theme='light_red.xml', invert_secondary=True) ``` -------------------------------- ### Custom Material Design Theme Creation Source: https://context7.com/un-gcpds/qt-material/llms.txt Shows how to create custom Material Design themes using Android XML color format or the built-in theme designer. Themes define color palettes and text colors for proper contrast. Custom XML themes can be applied directly. ```python # Create custom theme XML file (my_theme.xml) custom_theme_xml = """ #00e5ff #6effff #f5f5f5 #ffffff #e6e6e6 #000000 #000000 """ with open('my_theme.xml', 'w') as f: f.write(custom_theme_xml) # Apply custom theme from PySide6 import QtWidgets from qt_material import apply_stylesheet app = QtWidgets.QApplication([]) window = QtWidgets.QMainWindow() apply_stylesheet(app, theme='my_theme.xml', invert_secondary=True) window.show() app.exec() ``` -------------------------------- ### Customizing Stylesheets and Applying CSS Files Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/index.md This code shows how to define custom QPushButton styles and apply them. It also demonstrates extending the current stylesheet with a custom CSS file and dynamically changing the stylesheet at runtime by reading a file and appending its content. The 'setProperty' method is used to apply class styles. ```ipython3 QPushButton {{ color: {QTMATERIAL_SECONDARYCOLOR}; text-transform: none; background-color: {QTMATERIAL_PRIMARYCOLOR}; }} .big_button {{ height: 64px; }} apply_stylesheet(app, theme='light_blue.xml', css_file='custom.css') stylesheet = app.styleSheet() with open('custom.css') as file: app.setStyleSheet(stylesheet + file.read().format(**os.environ)) self.main.pushButton.setProperty('class', 'big_button') ``` -------------------------------- ### Runtime Theme Switching with QtStyleTools in Python Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.ipynb This Python code demonstrates how to change the theme of a Qt application at runtime by inheriting from QMainWindow and qt_material.QtStyleTools. The apply_stylesheet method is used to load different theme XML files. This allows for dynamic theme updates without restarting the application. ```python from qt_material import QtStyleTools from PySide6 import QtWidgets from PySide6.QtUiTools import QUiLoader from PySide6.QtWidgets import QMainWindow class RuntimeStylesheets(QMainWindow, QtStyleTools): def __init__(self): super().__init__() self.main = QUiLoader().load('main_window.ui', self) self.apply_stylesheet(self.main, 'dark_teal.xml') # self.apply_stylesheet(self.main, 'light_red.xml') # self.apply_stylesheet(self.main, 'light_blue.xml') ``` -------------------------------- ### Exporting qt-material Themes for Qt Implementations Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/index.md This code demonstrates how to export qt-material themes into local files (`.qss`, `.rcc`) that can be used in Qt implementations. It includes custom extra arguments for button colors, fonts, and environment settings. The generated files can be integrated into a PySide6 application. ```ipython3 from qt_material import export_theme extra = { # Button colors 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', # Font 'font_family': 'monoespace', 'font_size': '13px', 'line_height': '13px', # Density Scale 'density_scale': '0', # environ 'pyside6': True, 'linux': True, } export_theme(theme='dark_teal.xml', qss='dark_teal.qss', rcc='resources.rcc', output='theme', prefix='icon:/', invert_secondary=False, extra=extra, ) ``` -------------------------------- ### List Available Themes Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md This code snippet uses the `list_themes` function from the `qt_material` library to display all available stylesheet themes. Note that `qt_material` must be imported after PySide or PyQt. ```python from qt_material import list_themes list_themes() ``` -------------------------------- ### Export qt-material Theme for External Use Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Shows how to use the export_theme function to generate .qss and .rcc files from a theme, along with an icon folder, for integration into other Qt projects. ```python from qt_material import export_theme extra = { # Button colors 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', # Font 'font_family': 'monoespace', 'font_size': '13px', 'line_height': '13px', # Density Scale 'density_scale': '0', # environ 'pyside6': True, 'linux': True, } export_theme(theme='dark_teal.xml', qss='dark_teal.qss', rcc='resources.rcc', output='theme', prefix='icon:/', invert_secondary=False, extra=extra, ) import sys from PySide6 import QtWidgets from PySide6.QtCore import QDir from __feature__ import snake_case, true_property # Create application app = QtWidgets.QApplication(sys.argv) # Load styles with open('dark_teal.qss', 'r') as file: app.style_sheet = file.read() # Load icons QDir.add_search_path('icon', 'theme') ``` -------------------------------- ### Apply Stylesheet with Density Scale (Python) Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Applies a stylesheet to a Qt application with a custom density scale. The 'extra' dictionary is used to pass configuration options, including 'density_scale'. Requires the 'qt_material' library. ```python from qt_material import apply_stylesheet extra = { # Density Scale 'density_scale': '-2', } apply_stylesheet(app, 'default', invert_secondary=False, extra=extra) ``` -------------------------------- ### Integrate Exported qt-material Theme in PySide6 Application Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.ipynb This Python code shows how to load and apply the exported QSS and RCC files generated by export_theme into a PySide6 application. It demonstrates setting the stylesheet and adding search paths for icons, enabling the use of custom themes directly within a Qt application. ```python import sys from PySide6 import QtWidgets from PySide6.QtCore import QDir from PySide6.__feature__ import snake_case, true_property # Create application app = QtWidgets.QApplication(sys.argv) # Load styles with open('dark_teal.qss', 'r') as file: app.style_sheet = file.read() # Load icons QDir.add_search_path('icon', 'theme') # App window = QtWidgets.QMainWindow() checkbox = QtWidgets.QCheckBox(window) checkbox.text = 'CheckBox' window.show() app.exec() ``` -------------------------------- ### Apply Custom Fonts and Accent Colors to QPushButtons Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Demonstrates how to use the 'extra' argument in apply_stylesheet to define custom colors and fonts. It also shows how to apply these accent colors to QPushButtons using their 'class' property. ```python extra = { # Button colors 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', # Font 'font_family': 'Roboto', } apply_stylesheet(app, 'light_cyan.xml', invert_secondary=True, extra=extra) pushButton_danger.setProperty('class', 'danger') pushButton_warning.setProperty('class', 'warning')pushButton_success.setProperty('class', 'success') ``` -------------------------------- ### Integrate Exported Theme into PySide6 Application (Python) Source: https://github.com/un-gcpds/qt-material/blob/master/README.md Loads and applies a qt-material theme (QSS file and icons) into a PySide6 application. This code demonstrates how to set the stylesheet and add icon search paths. ```python import sys from PySide6 import QtWidgets from PySide6.QtCore import QDir from __feature__ import snake_case, true_property # Create application app = QtWidgets.QApplication(sys.argv) # Load styles with open('dark_teal.qss', 'r') as file: app.style_sheet = file.read() # Load icons QDir.add_search_path('icon', 'theme') # App window = QtWidgets.QMainWindow() checkbox = QtWidgets.QCheckBox(window) checkbox.text = 'CheckBox' window.show() app.exec() ``` -------------------------------- ### Configure QMenu Styling (Python) Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Configures specific styling for the QMenu widget within a Qt application. These settings are independent of the global density scale. Requires the 'qt_material' library and assumes 'extra' dictionary is already defined. ```python extra['QMenu'] = { 'height': 50, 'padding': '50px 50px 50px 50px', # top, right, bottom, left } ``` -------------------------------- ### Integrating Exported Theme into PySide6 Application Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/index.md This snippet shows how to load and apply an exported QSS stylesheet and set up icon search paths for a PySide6 application. It demonstrates the practical use of the files generated by the `export_theme` function. ```python import sys from PySide6 import QtWidgets from PySide6.QtCore import QDir from __feature__ import snake_case, true_property # Create application app = QtWidgets.QApplication(sys.argv) # Load styles with open('dark_teal.qss', 'r') as file: app.style_sheet = file.read() # Load icons QDir.add_search_path('icon', 'theme') ``` -------------------------------- ### Export qt-material Theme to QSS and RCC Files in Python Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.ipynb This Python snippet demonstrates exporting a qt-material theme into standalone QSS (Qt Style Sheet) and RCC (Resource Collection) files, making it usable in non-Python Qt environments. It includes defining custom extra parameters for colors, fonts, and environment settings, and then calls export_theme to generate the necessary files. ```python from qt_material import export_theme extra = { # Button colors 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', # Font 'font_family': 'monoespace', 'font_size': '13px', 'line_height': '13px', # Density Scale 'density_scale': '0', # environ 'pyside6': True, 'linux': True, } export_theme(theme='dark_teal.xml', qss='dark_teal.qss', rcc='resources.rcc', output='theme', prefix='icon:/', invert_secondary=False, extra=extra, ) ``` -------------------------------- ### Export qt-material Theme to Local Files (Python) Source: https://github.com/un-gcpds/qt-material/blob/master/README.md Exports a qt-material theme to local QSS, RCC, and icon files. This allows integration into Qt applications, including PySide6. The `extra` dictionary customizes theme elements like colors, fonts, and platform-specific settings. ```python from qt_material import export_theme extra = { # Button colors 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', # Font 'font_family': 'monoespace', 'font_size': '13px', 'line_height': '13px', # Density Scale 'density_scale': '0', # environ 'pyside6': True, 'linux': True, } export_theme(theme='dark_teal.xml', qss='dark_teal.qss', rcc='resources.rcc', output='theme', prefix='icon:/', invert_secondary=False, extra=extra, ) ``` -------------------------------- ### Extending Stylesheets with Custom CSS Source: https://context7.com/un-gcpds/qt-material/llms.txt Illustrates how to extend or override Material Design stylesheets with custom CSS rules. CSS files can reference theme colors using environment variables that are automatically populated by the theme engine. Custom classes can be applied to widgets. ```python # Create custom CSS file (custom.css) custom_css = """ QPushButton {{ color: {QTMATERIAL_SECONDARYCOLOR}; text-transform: none; background-color: {QTMATERIAL_PRIMARYCOLOR}; border-radius: 8px; }} .big_button {{ height: 64px; font-size: 16px; font-weight: bold; }} QLabel {{ color: {QTMATERIAL_PRIMARYTEXTCOLOR}; background-color: transparent; }} """ with open('custom.css', 'w') as f: f.write(custom_css) # Apply theme with custom CSS import sys from PySide6 import QtWidgets from qt_material import apply_stylesheet app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() button = QtWidgets.QPushButton('Click Me', window) # Apply base theme with CSS overrides apply_stylesheet(app, theme='dark_blue.xml', css_file='custom.css') # Apply custom class to specific widgets button.setProperty('class', 'big_button') window.show() app.exec() ``` -------------------------------- ### Apply Material Design Theme to Qt Application (Python) Source: https://context7.com/un-gcpds/qt-material/llms.txt Applies a Material Design theme to a Qt application or widget, configuring colors, fonts, icons, and styling. Supports PySide6, PySide2, PyQt5, and PyQt6. Accepts options for light/dark themes, custom colors via 'extra' dictionary, and CSS overrides through 'css_file'. ```python import sys from PySide6 import QtWidgets from qt_material import apply_stylesheet # Create application app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # Apply dark theme with custom configuration extra = { 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', 'font_family': 'Roboto', 'density_scale': '-1', # More compact layout } apply_stylesheet(app, theme='dark_teal.xml', invert_secondary=False, extra=extra) # Optionally apply custom CSS overrides apply_stylesheet(app, theme='light_blue.xml', css_file='custom.css', invert_secondary=True, extra=extra) window.show() app.exec() ``` -------------------------------- ### Access Theme Colors via Environment Variables with PySide6 Source: https://context7.com/un-gcpds/qt-material/llms.txt This snippet demonstrates how to apply a Qt-Material theme and then access the generated theme colors (primary, secondary, text colors) programmatically through environment variables. These variables can be used to customize widgets or stylesheets. ```python import os from PySide6 import QtWidgets from qt_material import apply_stylesheet app = QtWidgets.QApplication([]) window = QtWidgets.QMainWindow() # Apply theme (populates environment variables) apply_stylesheet(app, theme='dark_purple.xml') # Access theme colors via environment variables primary_color = os.environ.get('QTMATERIAL_PRIMARYCOLOR') primary_light = os.environ.get('QTMATERIAL_PRIMARYLIGHTCOLOR') secondary_color = os.environ.get('QTMATERIAL_SECONDARYCOLOR') secondary_light = os.environ.get('QTMATERIAL_SECONDARYLIGHTCOLOR') secondary_dark = os.environ.get('QTMATERIAL_SECONDARYDARKCOLOR') primary_text = os.environ.get('QTMATERIAL_PRIMARYTEXTCOLOR') secondary_text = os.environ.get('QTMATERIAL_SECONDARYTEXTCOLOR') theme_name = os.environ.get('QTMATERIAL_THEME') print(f"Theme: {theme_name}") print(f"Primary Color: {primary_color}") print(f"Secondary Color: {secondary_color}") # Use colors in custom widgets label = QtWidgets.QLabel(f'Primary: {primary_color}') label.setStyleSheet(f'background-color: {primary_color}; color: {primary_text};') window.setCentralWidget(label) window.show() app.exec() ``` -------------------------------- ### Apply Custom Stylesheets with Extra Arguments Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/index.md This snippet demonstrates how to apply stylesheets with custom accent colors and fonts using the `extra` argument in the `apply_stylesheet` function. The accent colors can be applied to QPushButtons by setting their 'class' property. ```ipython3 extra = { # Button colors 'danger': '#dc3545', 'warning': '#ffc107', 'success': '#17a2b8', # Font 'font_family': 'Roboto', } apply_stylesheet(app, 'light_cyan.xml', invert_secondary=True, extra=extra) pushButton_danger.setProperty('class', 'danger') pushButton_warning.setProperty('class', 'warning') pushButton_success.setProperty('class', 'success') ``` -------------------------------- ### Create Buttons with Semantic Colors using PySide6 Source: https://context7.com/un-gcpds/qt-material/llms.txt This snippet demonstrates how to create QPushButton widgets in PySide6 and assign semantic color classes ('danger', 'warning', 'success') for styling. It sets up a basic QVBoxLayout to arrange the buttons. ```python from PySide6 import QtWidgets central_widget = QtWidgets.QWidget() layout = QtWidgets.QVBoxLayout(central_widget) delete_button = QtWidgets.QPushButton('Delete') delete_button.setProperty('class', 'danger') warning_button = QtWidgets.QPushButton('Warning') warning_button.setProperty('class', 'warning') save_button = QtWidgets.QPushButton('Save') save_button.setProperty('class', 'success') layout.addWidget(delete_button) layout.addWidget(warning_button) layout.addWidget(save_button) window.setCentralWidget(central_widget) window.show() app.exec() ``` -------------------------------- ### Defining Semantic Button Colors Source: https://context7.com/un-gcpds/qt-material/llms.txt Explains how to define semantic colors (danger, warning, success) for buttons to indicate different action types. These colors are applied using Qt's property system without modifying the base stylesheet, providing visual cues for action states. ```python from PySide6 import QtWidgets from qt_material import apply_stylesheet import sys app = QtWidgets.QApplication(sys.argv) window = QtWidgets.QMainWindow() # Configure extra colors extra = { 'danger': '#dc3545', # Red for destructive actions 'warning': '#ffc107', # Yellow for caution 'success': '#17a2b8', # Green/cyan for success 'font_family': 'Roboto', } apply_stylesheet(app, theme='light_cyan.xml', invert_secondary=True, extra=extra) ``` -------------------------------- ### Custom Stylesheet Modifications Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.md Illustrates how to override default stylesheets for custom changes, such as modifying QPushButton appearance and creating larger buttons. It also covers extending stylesheets and changing them dynamically at runtime. ```python QPushButton { color: {QTMATERIAL_SECONDARYCOLOR}; text-transform: none; background-color: {QTMATERIAL_PRIMARYCOLOR}; } .big_button { height: 64px; } apply_stylesheet(app, theme='light_blue.xml', css_file='custom.css') stylesheet = app.styleSheet() with open('custom.css') as file: app.setStyleSheet(stylesheet + file.read().format(**os.environ)) self.main.pushButton.setProperty('class', 'big_button') ``` -------------------------------- ### Configure Density Scale with Python Source: https://github.com/un-gcpds/qt-material/blob/master/docs/source/notebooks/readme.ipynb Sets the density scale for the Qt Material stylesheet. The 'density_scale' is an extra argument that modifies the visual density of UI elements. It defaults to 0 and accepts string values. This configuration is applied using the 'apply_stylesheet' function. ```python extra = { # Density Scale 'density_scale': '-2', } apply_stylesheet(app, 'default', invert_secondary=False, extra=extra) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.