Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] Is it possible to display two fonts in one label?

[Solved] Is it possible to display two fonts in one label?

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        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.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved