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.Fit ,WrapMode and MaximumLineCount
Forum Updated to NodeBB v4.3 + New Features

Text.Fit ,WrapMode and MaximumLineCount

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 2 Posters 1.6k 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.
  • A Offline
    A Offline
    Anita
    wrote on last edited by
    #1

    Hi,

    I wanted to Fit a Text within 2 lines and I have provided the wrap mode as Text.Wrap. and maxlineCount as 2.
    Ex:
    Text {
    width:30
    height:30
    fontSize:12
    maximumLineCount: 2
    fontSizeMode: Text.Fit
    font.pixelSize:12
    wrapMode: Text.Wrap
    minimumPixelSize: -1
    text: "ABCD EFGH IJKL"
    }
    The output which i recieve is only :
    ABCD
    EFGH.

    I Require the entire string to be displayed .
    The Text Wraps into 2 lines, but the entire text is not fit.
    Am i missing some property which i would require to be set?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      If the text does not fit, you need to either set the elide property or if you don't want that, you need to make the text wider so that it fits properly (modify width).

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anita
        wrote on last edited by
        #3

        @sierdzio said in Text.Fit ,WrapMode and MaximumLineCount:

        Hi Sierdzio,

        The String is a dynamic string in my Application. I cannot elide the string nor can i increase the width of the text, But I am ok with reducing the font size to fit within the set boundary. Is there a way in which this can be handled?

        sierdzioS 1 Reply Last reply
        0
        • A Anita

          @sierdzio said in Text.Fit ,WrapMode and MaximumLineCount:

          Hi Sierdzio,

          The String is a dynamic string in my Application. I cannot elide the string nor can i increase the width of the text, But I am ok with reducing the font size to fit within the set boundary. Is there a way in which this can be handled?

          sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @Anita said in Text.Fit ,WrapMode and MaximumLineCount:

          @sierdzio said in Text.Fit ,WrapMode and MaximumLineCount:

          Hi Sierdzio,

          The String is a dynamic string in my Application. I cannot elide the string nor can i increase the width of the text, But I am ok with reducing the font size to fit within the set boundary. Is there a way in which this can be handled?

          Yes, although it's not straightforward. You need to use FontMetrics or TextMetrics to figure out a proper text size which will fit the space you have available.

          (Z(:^

          A 1 Reply Last reply
          0
          • sierdzioS sierdzio

            @Anita said in Text.Fit ,WrapMode and MaximumLineCount:

            @sierdzio said in Text.Fit ,WrapMode and MaximumLineCount:

            Hi Sierdzio,

            The String is a dynamic string in my Application. I cannot elide the string nor can i increase the width of the text, But I am ok with reducing the font size to fit within the set boundary. Is there a way in which this can be handled?

            Yes, although it's not straightforward. You need to use FontMetrics or TextMetrics to figure out a proper text size which will fit the space you have available.

            A Offline
            A Offline
            Anita
            wrote on last edited by
            #5

            @sierdzio
            Hi,

            I could not use the fontMetrics/TextMetrics.
            I tried using :
            Text{
            id:twolinetxt
            width:30
            height: 30
            text: "ABCD EFGH IJKL"
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            // maximumLineCount: 1
            fontSizeMode: Text.Fit
            font.pixelSize:12
            lineHeight:(twolinetxt.height/2).toFixed(0)
            lineHeightMode:Text.FixedHeight
            wrapMode: Text.WordWrap
            minimumPixelSize: 1
            }

            where 2 in the line lineHeight:(twolinetxt.height/2).toFixed(0) specifies max line count.
            It has worked.
            Thank You :) .

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved