The Python Oracle

How to use Non-Standard Custom Font with Stylesheets?

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping

--

Chapters
00:00 How To Use Non-Standard Custom Font With Stylesheets?
01:03 Accepted Answer Score 16
01:19 Thank you

--

Full question
https://stackoverflow.com/questions/2795...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #fonts #pyqt #pyqt4 #qtstylesheets

#avk47



ACCEPTED ANSWER

Score 16


This is just a guess, because I cannot test it myself, but you could try loading the font before setting the stylesheet:

app = QtGui.QApplication(sys.argv)
QtGui.QFontDatabase.addApplicationFont('path/to/font')
# or load the font data directly
# QtGui.QFontDatabase.addApplicationFontFromData(fontdata)
stylesheet = open('mystylesheet.qss').read()
app.setStyleSheet(stylesheet)