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. Cut off text using QML Text element in a Layout.
Forum Update on Monday, May 27th 2025

Cut off text using QML Text element in a Layout.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 892 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.
  • E Offline
    E Offline
    EnriqueH73
    wrote on 2 Sept 2016, 19:51 last edited by
    #1

    Re: How to cut off text using QML Text element

    I understand "width" property must be set implicitly for edlide to work. However, we have a Text element in a Layout. We would like to truncate the text when gets too long. How can we use edlide in a Text type when is in a GridLayout?

    import QtQuick 2.5
    import QtQuick.Layouts 1.1
    
    
    Rectangle {
        width: 100
        height: 20
    
        GridLayout {
            clip: true
            anchors.fill: parent
    
            rows: 1
    
            Text{
               text: "veryverylooooooonnnnnnnnnnnggggggggggggggtext"
               width: 50
    
               elide: Text.ElideRight
            }
    
        }
    }
    
    1 Reply Last reply
    0
    • E Offline
      E Offline
      EnriqueH73
      wrote on 7 Sept 2016, 22:01 last edited by
      #2

      I was told to replace the "width" with "Layout.preferredWidth".

      That worked.

      1 Reply Last reply
      0

      1/2

      2 Sept 2016, 19:51

      • Login

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