I have a PyQt4 application that is created by an external .qss file using the following code:
... app = QtGui.QApplication(sys.argv) stylesheet = open('mystylesheet.qss').read() app.setStyleSheet(stylesheet) ...
Normally, I would like to specify the type of font that I like in the .qss file, for use as follows:
QMainWindow { font-family:arial; font-size:14px; }
But now I'm wondering, can I assign a custom font that I downloaded from the Internet (e.g. DroidSansMono (True Type Font)) instead of the standard Windows font?
NOTE. I am using 32 bit Windows XP SP3, with Python 2.7
UPDATE 1:
Based on Ehumoro's answer:
I can use a custom font downloaded by adding it to the font database before loading Stylesheet :
QtGui.QFontDatabase.addApplicationFont("Resources/Mf Wedding Bells.ttf")
After that, I can simply use the font name that I just added in the stylesheet, for example:
QLabel { font-family:Mf Wedding Bells; font-size:16px; }
And it works !!!
source share