Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML Label max width & multiline

I have a Label, but it should only be as long as the form. If the label is longer it should start on a new line. How can I realize this? I am using QtQuick Controls 2.0

My current code for the Label:

Label {
    id: lblMsg
    width: ApplicationWindow.width - 10 // not working
    text: "ajksdlldjklasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd"
    x: 20
    y: 20
}
like image 408
ioncodes Avatar asked Sep 12 '25 18:09

ioncodes


2 Answers

add this line:

 wrapMode: Text.Wrap
like image 55
pier_nasos Avatar answered Sep 14 '25 08:09

pier_nasos


Use the wrapMode property:

Label {
    id: lblMsg
    width: ApplicationWindow.width - 10
    text: "ajksdlldjklasdasdasdasdasdasdasdasdasdasdasdasdasdasdasd"
    x: 20
    y: 20
    wrapMode: Label.WordWrap
}

I'd suggest using Qt Quick Layouts to manage the layout of your application instead of sizing items manually.

like image 38
Mitch Avatar answered Sep 14 '25 08:09

Mitch