I have a font that has several font weights within one family (extra light, light, regular, semibold, bold, black). For this example, I'm using the free Google Webfont Source Sans Pro, but I've had the same issue with any font that has multiple weights (such as Avenir Next, a system font in Mac OS 10.8). In a Qt stylesheet, if I specify:
QLabel
{
font-family: Source Sans Pro;
font-size: 24px;
}
I get the "Regular" style of the font. If I specify:
QLabel
{
font-family: Source Sans Pro;
font-weight: bold;
font-size: 24px;
}
I get the bold version of the font. I can't figure out any combination that will give me anything other than regular or Bold. I tried putting the weight directly in the font-family (e.g., font-family: Source Sans Pro Light; ), I tried using Light, Semibold, etc. in the font-weight: specifier, I also tried using the numeric equivalents (Qt documentation says they're supposed to be values from 0 to 99 rather than the CSS x00 numbering). Nothing works.
EDIT: I did just try writing a quick program to sub in numbers between 0 and 999 for the font-weight property. Interestingly, I was able to get "light" if I put in anything between 0 and 399. 400 through 407 gave me "Regular," 408 through 599 gave me light again, then 600 or higher gave me semibold. This seems really odd, because now using numbers I can at least access "light" and "semibold." I still can't find any way to get the "Extra Light" or the "Black" weights.
My only question is, is this just impossible without resorting to custom code? I can get the exact font I want by creating a QFont as follows:
QFontDatabase db;
QFont = db.font("Source Sans Pro", "Semibold", 24 );
But obviously this means I can't use stylesheets (or worse, I have to write my own stylesheet parser or wrap the existing Qt one or something). This seems a little hard to believe that this isn't possible with stylesheets. Are multi-weight fonts just poorly supported in Qt?