QML Label with HTML-Tags



  • 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.") 
                        }
    

  • Moderators

    @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>');
    


  • @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>');
     }
    

  • Moderators

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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.