@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#setStyleName
However, I got it to work by using QFontDatabase::font() which takes the style name.