Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Multiline alignment with Linebreak
Qt 6.12 LTS is out! See what's new in the release blog

Multiline alignment with Linebreak

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 712 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.
  • M Offline
    M Offline
    Meistermosher
    wrote on last edited by
    #1

    Hey ho.
    I just wanted to know if (and how ;) ) it's possible to achieve a centered alignment with a text which includes an escape character.

    Here's what I got so far:

    currentState.png

    My goal is to have it something like

    "Please use your RFID card or App
      to start the charging process"
    

    Here*s my code so far:

    
        Text{
            id: idleText
            anchors.top: currentImage.bottom
            anchors.horizontalCenter: currentImage.horizontalCenter
            color: "white"
            anchors.topMargin: 60
            text: qsTr("Please use your RFID card or App\nto start the charging process!")
            font.pointSize: 20
            font.family: "Helvetica"
        }
    

    I tried it with horizontal Alignment, and some other alignments, but I didn't find anything suitable. :(

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2
      anchors.horizontalCenter: parent.horizontalCenter
      horizontalAlignment: Text.AlignHCenter
      

      does the job

      Or alternatively you could constrain the width ot the Text and set wrapMode with horizontalAlignent also set to be responsive :

      Text {
          text: qsTr("Please use your RFID card or App to start the charging process!") // no \n here
          font.pointSize: 20
          width: parent.width
          padding: 60
          horizontalAlignment: Text.AlignHCenter
          wrapMode: Text.Wrap
      }
      
      M 1 Reply Last reply
      1
      • GrecKoG GrecKo
        anchors.horizontalCenter: parent.horizontalCenter
        horizontalAlignment: Text.AlignHCenter
        

        does the job

        Or alternatively you could constrain the width ot the Text and set wrapMode with horizontalAlignent also set to be responsive :

        Text {
            text: qsTr("Please use your RFID card or App to start the charging process!") // no \n here
            font.pointSize: 20
            width: parent.width
            padding: 60
            horizontalAlignment: Text.AlignHCenter
            wrapMode: Text.Wrap
        }
        
        M Offline
        M Offline
        Meistermosher
        wrote on last edited by
        #3

        @GrecKo Ah, thanks! That's awesome! Yeah, I think wrapping would be a bit cooler when it comes to localization!
        Thanks a lot!

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