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. Button height with '\n' character
Forum Updated to NodeBB v4.3 + New Features

Button height with '\n' character

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 542 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by
      #2

      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?

      1 Reply Last reply
      0
      • RajeeshRaveendranR Offline
        RajeeshRaveendranR Offline
        RajeeshRaveendran
        wrote on last edited by RajeeshRaveendran
        #3

        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

        1 Reply Last reply
        0

        • Login

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