Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-16818

Support specifying font height in QML Text elements

XMLWordPrintable

      It would be useful to enable setting the height of the font in the text element, in cases where locale would dictate a different font

      The idea is that you want to specify the height of the Text element and you want the font to be (automatically) selected so that it fits the height.

      Here's one example (qml) implementation of such feature:

      Text {
         property int desiredHeight
         property real downSizingFactor: 0.8 // Initial guess
      
         onDesiredHeightChanged: calculateFontSize()
         Component.onCompleted: calculateFontSize()
      
         function calculateFontSize() {
            font.pixelSize = downSizingFactor * desiredHeight
            if (height && desiredHeight > 3) {
               while (height < desiredHeight) { font.pixelSize++ }
               while (height > desiredHeight) { font.pixelSize-- }
            }
         downSizingFactor = font.pixelSize / height 
         }
      }
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            denexter Andrew den Exter (closed Nokia identity) (Inactive)
            hhartz Henrik Hartz (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes