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. How to center text in Label?
Forum Updated to NodeBB v4.3 + New Features

How to center text in Label?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 4.0k 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.
  • P Offline
    P Offline
    Pyroxar
    wrote on last edited by
    #1

    How to center text in Label?

    Label {
                    Layout.topMargin: 50
                    Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
                    Layout.fillWidth: true
                    text: "Vivamus pulvinar neque sit amet tellus ultrices, sit amet tempor diam mollis"
                    wrapMode: Text.WordWrap
                    font.pixelSize: 16
                    color: "#424242"
                }
    
    E YashpalY 2 Replies Last reply
    0
    • P Pyroxar

      How to center text in Label?

      Label {
                      Layout.topMargin: 50
                      Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
                      Layout.fillWidth: true
                      text: "Vivamus pulvinar neque sit amet tellus ultrices, sit amet tempor diam mollis"
                      wrapMode: Text.WordWrap
                      font.pixelSize: 16
                      color: "#424242"
                  }
      
      E Offline
      E Offline
      Eeli K
      wrote on last edited by
      #2

      @Pyroxar Label extends the Text type which has horizontalAlignment property.

      1 Reply Last reply
      0
      • P Pyroxar

        How to center text in Label?

        Label {
                        Layout.topMargin: 50
                        Layout.alignment: Qt.AlignTop | Qt.AlignHCenter
                        Layout.fillWidth: true
                        text: "Vivamus pulvinar neque sit amet tellus ultrices, sit amet tempor diam mollis"
                        wrapMode: Text.WordWrap
                        font.pixelSize: 16
                        color: "#424242"
                    }
        
        YashpalY Offline
        YashpalY Offline
        Yashpal
        wrote on last edited by
        #3

        @Pyroxar You can try something like this. And, I hope this is what you were looking for.

        Label {
            text: "Some Text"
            wrapMode: Text.WordWrap
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
        }
        
        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