UN-GCPDS / qt-material

Material inspired stylesheet for PySide2, PySide6, PyQt5 and PyQt6
https://qt-material.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
2.3k stars 242 forks source link

Different font/overriding fonts set by the script #9

Closed JackPieCZ closed 3 years ago

JackPieCZ commented 3 years ago

I'm using Century Gothic font in my script and I would like to use e.g. dark_blue theme too. For some reason, the apply_theme function sets all fonts to Roboto even after

  1. adding Century Gothics fonts to fonts folder
  2. changing font-family in material.css.template to CenturyGothic
  3. commenting out the add_fonts function in __init__.py

So, is there any "normal" way to change the font? If not, is it possible to add that parameter to apply_theme function? Thx in advance!

FuturisticGoo commented 3 years ago

+1. For a temporary workaround, I removed the font-family: {{primaryFont}}; from material.css.template and applied the required font accordingly in the main python script

font_id=QtGui.QFontDatabase.addApplicationFont("path/to/font")
font_family=QtGui.QFontDatabase.applicationFontFamilies(font_id)[0]
app.setFont(QtGui.QFont(font_family)) 

or just

app.setFont(QtGui.QFont("font name")) 

If that font is installed

YeisonCardona commented 3 years ago

Hi @JackPieCZ, as @FuturisticGoo says, you must use QFontDatabase to load fonts from local files.

After that, you can select the font family from apply_stylesheet with the argument extra

apply_stylesheet(app, theme='dark_blue.xml', extra={'font_family': 'CenturyGothic'})

There is an example in which I use two fonts, one installed on the system and one local.