Creating QFont for a very specific font family/style pair



  • I am subclassing QGraphicsTextItem, and am trying to set its font.

    I am writing this app for myself only, and have a very particular font I wish to use:

    Futura Condensed ExtraBold, which is on my system.

    I have created a QFontDatabase to look at how Qt registers my fonts. 'Futura' is what is listed under families. When I run:

    fontdatabase.styles(QString("Futura"))

    one of the return values is:

    PyQt4.QtCore.QString(u'Condensed ExtraBold')

    I just can't for the life of me figure out how to set the exact 'style' of a QFont. I see how to set it generically to bold, or to a certain weight, but in this case, that style, Condensed ExtraBold, is a totally different looking font than say, Bold Oblique, Condensed Light Oblique, etc, which are all styles of Futura.

    I only seem to be able to figure out how to hint at the style I might want. How can I explicitly use Futura Condensed ExtraBold?

    edit

    I should add, I've tried QFont("Futura Condensed ExtraBold"), and Qt defaults to some bogus font that is certainly not Futura Condensed ExtraBold.



  • I found a solution.

    I moved the specific .ttf I wanted to a resources directory in my app so it would be bundled with it in the future. I then used:

    QFontDatabase.addApplicationFont("resources/FuturaCondensedExtraBold.ttf")

    Once I had done so, I was actually not able to do this:

    QFont("FuturaCondensedExtraBold")

    but I could simple do

    QFont("Futura")

    and the style it would find was ExtraBold


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.