Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Use Text.RichText and fontSizeMode: Text.Fit together?



  • I tried to create a Text element with rich text that auto-fits font size to fill its parent:

    Rectangle {
               color: "white"
               width: 300
               height: 300
    
               Text {
                            text: "12<span style=\"font-weight:100\">3</span>"
                            fontSizeMode: Text.Fit                      
                            font.pointSize: 80
                            textFormat: Text.RichText
                            anchors.fill: parent
                            minimumPointSize: 20
               }
    }
    

    However, it only works when I remove textFormat: Text.RichText. Otherwise, the text is not scaled.
    It works with textFormat: Text.StyledText, but then I can't use advanced formattings (I need the font weight to be changed).

    Is it possible to achieve auto fitting with rich text somehow?


Log in to reply