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. Text height
Qt 6.11 is out! See what's new in the release blog

Text height

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.8k Views 2 Watching
  • 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.
  • T Offline
    T Offline
    Trikrista
    wrote on last edited by
    #1

    How to make so that the height of the text has been equal to the height of a rectangle in which the text is?

    I'm sorry for my bad English

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!
      The following should work:

          Rectangle {
              width: 300
              height: 100
      
              Text {
                  text: "Hallo!"
                  font.pixelSize: parent.height
                  anchors.centerIn: parent
              }
          }
      
      1 Reply Last reply
      0
      • T Offline
        T Offline
        Trikrista
        wrote on last edited by
        #3

        obtained the margin on the top and bottom of the text
        That is, the height of the text < the height of the rectangle

        image

        I'm sorry for my bad English

        ? 1 Reply Last reply
        0
        • T Trikrista

          obtained the margin on the top and bottom of the text
          That is, the height of the text < the height of the rectangle

          image

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          This is a bit better as it seems to use contentHeight internally:

              Rectangle {
                  width: 300
                  height: 100
                  anchors.centerIn: parent
          
                  Text {
                      text: "Äp!"
                      anchors.fill: parent
                      fontSizeMode: Text.VerticalFit
                      font.pixelSize: 1000
                  }
              }
          

          But still "Hallo!" is not fully scaled up. I think the problem stems from the fact that contentHeight doesn't return the actual bounding box of the rendered text but the sum of the cap height and descender height.

          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