Button height with '\n' character



  • Hi all,
    this probably is a very silly question but ATM I can't find solution.
    I have the following Button:

    Button {
       text: "aaaa\nbbbb"
       anchors.top: parent.top   
       anchors.margins: 15
       width: parent.width
    }
    

    the Button's height doesn't consider the new line so part of the text is cuts.
    I could force height by hand in pixel but I'd prefer to let Button to find it's natural height.

    Thanks

    Luca



  • I found a workaround:

    Button {
       anchors.top: parent.top   
       anchors.margins: 15
       width: parent.width
       height: childrenRect.height
       Text {
          text: "aaaa\nbbbb"
       }
    }
    

    is this the only solution?



  • Hi Luca,

    try this. Hope this is what u want.

    Button {
        id: button1
        width: 50
        height: labelText.height
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        style: ButtonStyle {
            background: Rectangle {
                color: "red" /// Give a proper BG color.
            }
            label: Text{
                id: labelText
                text: "Aaaaaaaa Bbbbbbbb Ccccccc"
                wrapMode: Text.WordWrap
            }
        }
    }
    

    Regards,
    Rajeesh Raveendran


Log in to reply
 

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