KFox
KFox

Reputation: 1266

Baffling behavior from QFontDatabase

I am trying to load a font into my application. Logically, I want to load more than one font weight, but that's where the problem arises.

I have two font files, "PFD-Black.ttf" and "PFD-Regular.ttf". I want to use them both, so I load them both using this code:

fontid_regular = QFontDatabase.addApplicationFont("PFD-Regular.ttf")
fontid_black = QFontDatabase.addApplicationFont("PFD-Black.ttf")

I then get the family name, like so:

familyname = fontdb.applicationFontFamilies(fontid_black)[0]

Note that I have tried using fontid_regular as well but to no avail. Then I attempt to use the font for a QLabel:

lab = QLabel("My Font Window")
font = QFont(familyname)
lab.setFont(font)
lab.show()

That is the extent of my code, other than the boilerplate imports and QApplication.exec_() call.

This does not work (which may be obvious since I'm asking a question on SO about it), the label shows up in the default font.

This is when is doesn't work

The baffling part about my problem, is that when I comment out the line fontid_regular = QFontDatabase.addApplicationFont("PFD-Regular.ttf") the bold font shows.

This is when it kind of works

This is some level of workingness (for lack of a better word), but I am not able to use the regular weight font. It should also be noted that commenting out the line where I load "PFD-Black.ttf" does not fix the issue.

Note that I have seen this question, but no matter what mutations I perform on my code, I cannot make that solution work for me, so please don't mark this question as a duplicate of that one.

Upvotes: 4

Views: 1775

Answers (1)

KFox
KFox

Reputation: 1266

The problem has been solved in the comments above: it turned out that there was a problem with the font I was using.

Upvotes: 1

Related Questions