Cut off text using QML Text element in a Layout.



  • 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
            }
    
        }
    }
    


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

    That worked.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.