Does QFont::setStyleName work at all?
-
I tried to set the style name of fonts and none of the seem to work on Windows. Here's the code:
QFontDatabase fdb; auto fonts = fdb.families(); for(auto f:fonts) { auto styles = fdb.styles(f); for(auto s:styles) { QFont font(f); font.setStyleName(s); font.setPixelSize(13); auto label = new QLabel(QString::fromLatin1("%1: %2").arg(f).arg(s)); label->setFont(font); layout->addWidget(label); } }
And all the fonts with the same family render the same regardless of style name set. Is this a know issue?
-
hi
For the read method it says"depends on system font support, thus only works for OS X and X11 so far. On Windows irregular styles will be added as separate font families so there is no need for this."
http://doc.qt.io/qt-5.5/qfont.html#styleName
So maybe it has no effect on Windows?
-
@stephenju said:
fontsampler
ok that is good news then.
Can work.Have you checked your values again the values used in
QFont font(family, size, weight, italic); ?
in the sample. -
@mrjj I check and tried to replicate what the sample does but still doesn't work. I do notice the sample code uses the font in QTextDocument. Not sure if it matters.
Also, from the documentation, weight and italic shouldn't matter once you set the style name
http://doc.qt.io/qt-5/qfont.html#setStyleNameHowever, I got it to work by using QFontDatabase::font() which takes the style name.