Package: qt-material
Qt-MaterialThis is another stylesheet forPySide6,PySide2,PyQt5andPyQt6, which looks like Material Design (close enough).There is some custom dark themes:And light:NavigationInstallUsageThemesCustom colorsUsageLight themesEnviron variablesAlternative QPushButtons and custom fontsCustom stylesheetsRun examplesNew themesChange theme in runtimeExport themeDensity scaleTroubleshootsInstallpipinstallqt-materialUsageimportsysfromPySide6importQtWidgets# from PySide2 import QtWidgets# from PyQt5 import QtWidgetsfromqt_materialimportapply_stylesheet# create the application and the main windowapp=QtWidgets.QApplication(sys.argv)window=QtWidgets.QMainWindow()# setup stylesheetapply_stylesheet(app,theme='dark_teal.xml')# runwindow.show()app.exec_()Themesfromqt_materialimportlist_themeslist_themes()WARNING:root:qt_material must be imported after PySide or PyQt!





['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']Custom colorsColor Toolis the best way to generate new themes, just choose colors and export asAndroid XML, the theme file must look like:<!--?xmlversion="1.0"encoding="UTF-8"?--><resources><colorname="primaryColor">#00e5ff</color><colorname="primaryLightColor">#6effff</color><colorname="secondaryColor">#f5f5f5</color><colorname="secondaryLightColor">#ffffff</color><colorname="secondaryDarkColor">#e6e6e6</color><colorname="primaryTextColor">#000000</color><colorname="secondaryTextColor">#000000</color></resources>Save it asmy_theme.xmlor similar and apply the style sheet from Python.apply_stylesheet(app,theme='dark_teal.xml')Light themesLight themes will need to addinvert_secondaryargument asTrue.apply_stylesheet(app,theme='light_red.xml',invert_secondary=True)Environ variablesThere is a environ variables related to the current theme used, these variables are forconsult purpose only.Environ variableDescriptionExampleQTMATERIAL_PRIMARYCOLORPrimary color#2979ffQTMATERIAL_PRIMARYLIGHTCOLORA bright version of the primary color#75a7ffQTMATERIAL_SECONDARYCOLORSecondary color#f5f5f5QTMATERIAL_SECONDARYLIGHTCOLORA bright version of the secondary color#ffffffQTMATERIAL_SECONDARYDARKCOLORA dark version of the primary color#e6e6e6QTMATERIAL_PRIMARYTEXTCOLORColor for text over primary background#000000QTMATERIAL_SECONDARYTEXTCOLORColor for text over secondary background#000000QTMATERIAL_THEMEName of theme usedlight_blue.xmlAlternative QPushButtons and custom fontsThere is anextraargument for accent colors and custom fonts.extra={# Button colors'danger':'#dc3545','warning':'#ffc107','success':'#17a2b8',# Font'font_family':'Roboto',}apply_stylesheet(app,'light_cyan.xml',invert_secondary=True,extra=extra)The accent colors are applied toQPushButtonwith the correspondingclassproperty:pushButton_danger.setProperty('class','danger')pushButton_warning.setProperty('class','warning')pushButton_success.setProperty('class','success')Custom stylesheetsCustom changes can be performed by overwriting the stylesheets, for example:QPushButton{{color:{QTMATERIAL_SECONDARYCOLOR};text-transform:none;background-color:{QTMATERIAL_PRIMARYCOLOR};}}.big_button{{height:64px;}}Then, the current stylesheet can be extended just with:apply_stylesheet(app,theme='light_blue.xml',css_file='custom.css')The stylesheet can also be changed on runtime by:stylesheet=app.styleSheet()withopen('custom.css')asfile:app.setStyleSheet(stylesheet+file.read().format(**os.environ))And the class style can be applied with thesetPropertymethod:self.main.pushButton.setProperty('class','big_button')Run examplesA window with almost all widgets (see the previous screenshots) are available to test all themes andcreate new ones.gitclonehttps://github.com/UN-GCPDS/qt-material.gitcdqt-materialpythonsetup.pyinstallcdexamples/full_featurespythonmain.py--pyside6New themesDo you have a custom theme? it looks good? create apull requestinthemes folderand share it with all users.Change theme in runtimeThere is aqt_material.QtStyleToolsclass that must be inherited along toQMainWindowfor change themes in runtime using theapply_stylesheet()method.classRuntimeStylesheets(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 stylesheets in a menuA customstylesheets menucan be added to a project for switching across all default available themes.classRuntimeStylesheets(QMainWindow,QtStyleTools):def__init__(self):super().__init__()self.main=QUiLoader().load('main_window.ui',self)self.add_menu_theme(self.main,self.main.menuStyles)Create new themesA simple interface is available to modify a theme in runtime, this feature can be used to create a new theme, the theme file is created in the main directory asmy_theme.xmlclassRuntimeStylesheets(QMainWindow,QtStyleTools):def__init__(self):super().__init__()self.main=QUiLoader().load('main_window.ui',self)self.show_dock_theme(self.main)A full set of examples are available in theexmaples directoryExport themeThis feature able to useqt-materialthemes intoQtimplementations using only local files.fromqt_materialimportexport_themeextra={# 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,)This script will generate bothdark_teal.qssandresources.rccand a folder with all theme icons calledtheme.The files generated can be integrated into aPySide6application just with:importsysfromPySide6importQtWidgetsfromPySide6.QtCoreimportQDirfrom__feature__importsnake_case,true_property# Create applicationapp=QtWidgets.QApplication(sys.argv)# Load styleswithopen('dark_teal.qss','r')asfile:app.style_sheet=file.read()# Load iconsQDir.add_search_path('icon','theme')# Appwindow=QtWidgets.QMainWindow()checkbox=QtWidgets.QCheckBox(window)checkbox.text='CheckBox'window.show()app.exec()This files can also be used into nonPythonenvirons likeC++.Density scaleTheextraarguments also include an option to set thedensity scale, by default is0.extra={# Density Scale'density_scale':'-2',}apply_stylesheet(app,'default',invert_secondary=False,extra=extra)TroubleshootsQMenuQMenuhas multiple rendering for each Qt backend, and for each operating system. Even can be related with the style, likefusion. Then, theextraargument also supportsQMenuparameters to configure this widgest for specific combinations. This options are not affected bydensity scale.extra['QMenu']={'height':50,'padding':'50px 50px 50px 50px',# top, right, bottom, left}