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 limit the text width with the restriction of parent width
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to limit the text width with the restriction of parent width

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.6k Views 1 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
    av2306
    wrote on last edited by
    #1

    Hi,

    @Label {
    id: test
    width: 100
    height: 30
    Text{
    color: 'red'
    //anchors adjustment
    text: qsTr("sometext") //if sometext has 256 characters, lengthy text appears in adjacent controls.
    }
    }
    @

    How to truncate the test as per label width? I have width in pixels. Want to control text. any idea.

    Thanks.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Set clip: true for Text element.

      157

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vikaspachdha
        wrote on last edited by
        #3

        @
        Label {
        id: test
        width: 100
        height: 30
        Text{
        color: 'red'
        width: parent.width // The width of the text is same as parent
        anchors.centerIn:parent // The text is placed in center of the parent
        elide: Text.AlignRight // Show ellipses '...' if text is not able to fit horizontally
        text: qsTr("sometext")
        }
        }

        @

        You should avoid clipping. As per the Performance Considerations And Suggestions document "Clipping is a visual effect, NOT an optimization. It increases (rather than reduces) complexity for the renderer."

        1 Reply Last reply
        0
        • A Offline
          A Offline
          av2306
          wrote on last edited by
          #4

          Hi Vikas,

          "clip:true" worked fine for me.

          "elide" didn't solve the issue. This Label used inside Column.

          Thanks.

          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