I understand the "width" property must be set implicitly for elide to work. However, I have a Text element in a Layout. I would like to truncate the text when it gets too long. How can I use elide in a Text type when it 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
}
}
}
Change width: 50 to Layout.preferredWidth: 50
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"
Layout.preferredWidth: 50
elide: Text.ElideRight
}
}
}
Result:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With