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

fontsizemode

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

    hi
    I am trying to use fontsizemode because I have to make size of text small based on text length

    my code:

    import QtQuick 2.9
    import QtQuick.Window 2.2
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle
        {
        color: "Red"
        height:50
        width:50
    
        Text { text: "Hello"; fontSizeMode: Text.Fit; minimumPixelSize: 5; font.pixelSize: 50 }
    
    
        }
    
    }
    

    but it is not working is anything wrong in my program?

    0_1548325115344_d9676ffe-4329-4dd6-90b7-5edb0e7ba6b8-image.png

    1 Reply Last reply
    0
    • ashajgA Offline
      ashajgA Offline
      ashajg
      wrote on last edited by
      #2

      Solved this problem
      working code:

      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Rectangle
          {
          color: "Red"
          height:50
          width:50
      
          Text {
      width:parent.width
      height: parent.height
       text: "Hello"; fontSizeMode: Text.Fit; minimumPixelSize: 5; font.pixelSize: 50 }
      
      
          }
      
      }
      
      1 Reply Last reply
      0
      • K Offline
        K Offline
        krokstr
        wrote on last edited by
        #3

        Hello,

        If you want your text to be fitted in the Rectangle, just add the next line to your Text component:

            anchors.fill: parent
        

        Like this:

            Text {
                anchors.fill: parent
                text: "Hello";
                fontSizeMode: Text.Fit;
                minimumPixelSize: 5;
                font.pixelSize: 50
            }
        

        Now Text will have the same width and height as Rectangle. And using fontSizeMode: Text.Fit will fit both width and height of Rectangle. You can also use Text.HorizontalFit or Text.VerticalFit to fit in width or height.

        ashajgA 1 Reply Last reply
        2
        • K krokstr

          Hello,

          If you want your text to be fitted in the Rectangle, just add the next line to your Text component:

              anchors.fill: parent
          

          Like this:

              Text {
                  anchors.fill: parent
                  text: "Hello";
                  fontSizeMode: Text.Fit;
                  minimumPixelSize: 5;
                  font.pixelSize: 50
              }
          

          Now Text will have the same width and height as Rectangle. And using fontSizeMode: Text.Fit will fit both width and height of Rectangle. You can also use Text.HorizontalFit or Text.VerticalFit to fit in width or height.

          ashajgA Offline
          ashajgA Offline
          ashajg
          wrote on last edited by
          #4

          @krokstr Thank you.

          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