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. How to adapt PixelSize if Text width is fixed
Forum Updated to NodeBB v4.3 + New Features

How to adapt PixelSize if Text width is fixed

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 945 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.
  • F Offline
    F Offline
    Fheanor
    wrote on last edited by
    #1

    Hello,

    I have trouble to do a simple thing.

    I have a Text Component that cannot have a width bigger than 300 (this is an example).
    I have a default font.pixelSize . However, if my text has too many characters, I would like to reduce the pixelSize of it.

    Example:

    Text {
         ont.pixelSize: 20
            text : myText
            
        //If Text width > 300, I would like to change font.pixelSize
            
    }
    

    Any suggestion ? Thanks a lot

    SeeLookS 1 Reply Last reply
    0
    • F Fheanor

      Hello,

      I have trouble to do a simple thing.

      I have a Text Component that cannot have a width bigger than 300 (this is an example).
      I have a default font.pixelSize . However, if my text has too many characters, I would like to reduce the pixelSize of it.

      Example:

      Text {
           ont.pixelSize: 20
              text : myText
              
          //If Text width > 300, I would like to change font.pixelSize
              
      }
      

      Any suggestion ? Thanks a lot

      SeeLookS Offline
      SeeLookS Offline
      SeeLook
      wrote on last edited by
      #2
      Text {
          font.pixelSize: 20 * (width > 300 ? 300 / width : 1 )
      }
      

      but it causes property binding loop...
      However scale could do the trick:

      Text {
          scale: width > 300 ? 300 / width : 1 
      }
      
      1 Reply Last reply
      0
      • jpnurmiJ Offline
        jpnurmiJ Offline
        jpnurmi
        wrote on last edited by
        #3

        See Text::fontSizeMode. There's Text.HorizontalFit.

        1 Reply Last reply
        4
        • F Offline
          F Offline
          Fheanor
          wrote on last edited by
          #4

          Thanks, this is what I need.
          Have a good day

          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