Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Label with HTML-Tags
Forum Update on Monday, May 27th 2025

QML Label with HTML-Tags

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
5 Posts 2 Posters 2.8k 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.
  • M Offline
    M Offline
    Manu19
    wrote on 24 Aug 2017, 10:08 last edited by
    #1

    Hi devs, how can I set the font-weight inside a html-tag? I have tried the following code, but it doesn't work. Can anyone help me?

    Code:

    Label{
                            topPadding: 10
                            leftPadding: 20
                            rightPadding: 20
                            font.weight: Font.Light
                            wrapMode: Text.WordWrap
                            textFormat: Text.RichText
                            text: qsTr("<font font-weight:medium>The first step</font> is to select a tool. You can choose it from a predefined list.") 
                        }
    
    R 1 Reply Last reply 24 Aug 2017, 10:47
    0
    • M Manu19
      24 Aug 2017, 10:08

      Hi devs, how can I set the font-weight inside a html-tag? I have tried the following code, but it doesn't work. Can anyone help me?

      Code:

      Label{
                              topPadding: 10
                              leftPadding: 20
                              rightPadding: 20
                              font.weight: Font.Light
                              wrapMode: Text.WordWrap
                              textFormat: Text.RichText
                              text: qsTr("<font font-weight:medium>The first step</font> is to select a tool. You can choose it from a predefined list.") 
                          }
      
      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 24 Aug 2017, 10:47 last edited by
      #2

      @Manu19 said in QML Label with HTML-Tags:

      <font font-weight:medium>

      this is not valid HTML!

      text: qsTr('<font font-weight="medium">bold text</font>');
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Manu19
        wrote on 24 Aug 2017, 11:44 last edited by
        #3

        @raven-worx said in QML Label with HTML-Tags:

        '<font font-weight="medium">bold text</font>'

        Thank you for your answer, but your code doesn't work too. My Code:

        Label {
              topPadding: 10
              leftPadding: 20
              rightPadding: 20
              wrapMode: Text.WordWrap
              font.weight: Font.Light
              textFormat: Text.RichText
              text: qsTr('<font font-weight="bold">bold text</font>');
         }
        
        R 1 Reply Last reply 24 Aug 2017, 11:54
        1
        • M Manu19
          24 Aug 2017, 11:44

          @raven-worx said in QML Label with HTML-Tags:

          '<font font-weight="medium">bold text</font>'

          Thank you for your answer, but your code doesn't work too. My Code:

          Label {
                topPadding: 10
                leftPadding: 20
                rightPadding: 20
                wrapMode: Text.WordWrap
                font.weight: Font.Light
                textFormat: Text.RichText
                text: qsTr('<font font-weight="bold">bold text</font>');
           }
          
          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 24 Aug 2017, 11:54 last edited by
          #4

          @Manu19
          i see. The font element only supports the family-, color- and size-attributes. See here.
          use <b> tags instead.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Manu19
            wrote on 24 Aug 2017, 12:12 last edited by
            #5

            My code was only a example. I have tried "bold", but bold is a little bit strong for me. Thank you for your time and work.

            1 Reply Last reply
            0

            1/5

            24 Aug 2017, 10:08

            • Login

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