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. [solved] How to make Text font size to be auto adjusted

[solved] How to make Text font size to be auto adjusted

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 15.3k 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
    morte
    wrote on 6 Nov 2014, 21:36 last edited by
    #1

    How to make Text font size to be adjusted depending on parent width & height?

    Here is code snippet:
    @
    Item {
    width: 200 // that value will vary
    height: 100 // that value will vary

    Text {
    id: label
    anchors.top: parent.top; anchors.left: parent.left
    font.pointSize: 10 // this can be static size
    text: "current"
    }

    Text {
    id: data
    anchors.top: label.bottom; anchors.bottom: parent.bottom;
    anchors.left: parent.left;
    anchors.topMargin: 5
    font.pointSize: 40 // this should resize to fit parent size
    text: "100"
    }

    Text {
    id: units
    anchors.bottom: data.bottom; anchors.left: data.right
    anchors.leftMargin: 5
    font.pointSize: data.font.pointSize/2 // this will be resized aswell
    text: "mA"
    }
    }
    @

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gianluca
      wrote on 7 Nov 2014, 08:56 last edited by
      #2

      It's very simple.
      You need to explicit specify the width and height of your Text item and then specify minimumPointSize and fontSizeMode:
      @
      Text {
      width: parent.width
      height: parent.height
      font.pointSize: 100
      minimumPointSize: 10
      fontSizeMode: Text.Fit
      }
      @

      fontSizeMode doesn't work if you don't explicit set the width and height to the Text items. Anchors is not enough.

      1 Reply Last reply
      3
      • M Offline
        M Offline
        morte
        wrote on 18 Nov 2014, 16:35 last edited by
        #3

        Thanks, I've tested that and have notice that it also works with anchors.

        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