Export Guide¶
This notebook demonstrates how to export a Qt-Material theme into local .qss and .rcc files for use in Python or C++ applications, even without needing the Python package at runtime.
Export theme¶
You can export a complete theme including styles and resources using the export_theme() function:
[ ]:
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',
# Environment hints
'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,
)
This command will generate:
dark_teal.qss: the compiled stylesheetresources.rcc: the icon archiveA folder named
theme/with all required icons
Using the exported theme in PySide6¶
[ ]:
import sys
from PySide6 import QtWidgets
from PySide6.QtCore import QDir
app = QtWidgets.QApplication(sys.argv)
# Load stylesheet
with open('dark_teal.qss', 'r') as file:
app.setStyleSheet(file.read())
# Register icon prefix
QDir.addSearchPath('icon', 'theme')
# Simple test window
window = QtWidgets.QMainWindow()
checkbox = QtWidgets.QCheckBox(window)
checkbox.setText('CheckBox')
window.show()
app.exec()
Cross-language support¶
The exported .qss and .rcc files can also be integrated into non-Python projects, such as C++/Qt applications, without requiring qt-material or Python at all.
New themes¶
Do you have a custom theme? Does it look great? Feel free to contribute! Create a pull request in the themes folder and share it with the community.