[Solved] Is it possible to display two fonts in one label?
I have written a project that runs on a Linux target. I've installed two fonts: Century Gothic and unifont. The project was written in English, but there are translations for 10 other languages. Century Gothic is used as the default font when the application is displaying English, French, Italian, etc., but unifont is used when we switch to Chinese or Japanese.
The translation part of the project works fine - I can see the Chinese and Japanese characters just fine. The problem comes in when numbers are displayed. The font style for numbers in unifont looks completely different than that of Century Gothic.
As an example, take the following line of code:
ui->label_16->SetText(tr("Distance is 16.3 m"));
When we're in English or any other "western" language, it looks good. When we switch to Chinese or Japanese, though, I see the translation of "Distance is" without a problem, but the "16.3 m" has a completely different look than labels where only a number is displayed (because those fields are in Century Gothic). Is there any way to display the first part ("Distance is") of the message in unifont but display the second part ("16.3 m") in Century Gothic?
AFAIK, no. You could try using html but I can't guaranty. The most simple solution would be to use two QLabel.
Hope it helps
Try enforcing the font using HTML...
ui->label_16->setText(tr("Distance is <font face="century gothic">16.3m</font>"));
...or just don't translate the numbers:
ui->label_16->setText(tr("Distance is ") + "16.3m"));
(Note: I haven't tested either of these methods)
See "here":http://qt-project.org/doc/qt-5/richtext-html-subset.html for a list of supported rich text tags.