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. Align Qt Quick element vertically in ColumnLayout
Forum Updated to NodeBB v4.3 + New Features

Align Qt Quick element vertically in ColumnLayout

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 2.8k 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.
  • D Offline
    D Offline
    David Demelier
    wrote on 13 Sept 2018, 14:57 last edited by
    #1

    Hi,

    I would like to have a centered label and two buttons at the bottom of the screen, something like this:

    +--------------------+
    |                    |
    |                    |
    |                    |
    |       Hello        |
    |                    |
    |                    |
    |                    |
    |       [play]       |
    |       [quit]       |
    +--------------------+
    

    Here is my code, everything works except the label is not centered vertically but centered horizontally at the top of the screen.

    import QtQuick 2.0
    import QtQuick.Layouts 1.3
    import QtQuick.Controls 2.2
    
    ColumnLayout {
        Label {
            text: "Save the Ball!"
            font.pointSize: 60
            Layout.fillHeight: true
            Layout.alignment: Qt.AlignCenter
        }
    
        Button {
            text: "Play"
            Layout.fillWidth: true
        }
    
        Button {
            text: "Quit"
            Layout.fillWidth: true
        }
    }
    

    Do you have an idea what I'm doing wrong?

    Thanks!

    G 1 Reply Last reply 13 Sept 2018, 14:59
    0
    • D David Demelier
      13 Sept 2018, 14:57

      Hi,

      I would like to have a centered label and two buttons at the bottom of the screen, something like this:

      +--------------------+
      |                    |
      |                    |
      |                    |
      |       Hello        |
      |                    |
      |                    |
      |                    |
      |       [play]       |
      |       [quit]       |
      +--------------------+
      

      Here is my code, everything works except the label is not centered vertically but centered horizontally at the top of the screen.

      import QtQuick 2.0
      import QtQuick.Layouts 1.3
      import QtQuick.Controls 2.2
      
      ColumnLayout {
          Label {
              text: "Save the Ball!"
              font.pointSize: 60
              Layout.fillHeight: true
              Layout.alignment: Qt.AlignCenter
          }
      
          Button {
              text: "Play"
              Layout.fillWidth: true
          }
      
          Button {
              text: "Quit"
              Layout.fillWidth: true
          }
      }
      

      Do you have an idea what I'm doing wrong?

      Thanks!

      G Offline
      G Offline
      Gojir4
      wrote on 13 Sept 2018, 14:59 last edited by
      #2

      @David-Demelier
      Hi,
      Because the text is aligned at top inside the Label, this should do what you want:

       Label {
              text: "Save the Ball!"
              font.pointSize: 60
              verticalAlignment: Text.AlignVCenter
              Layout.fillHeight: true
              Layout.alignment: Qt.AlignCenter
          }
      
      
      1 Reply Last reply
      2
      • D Offline
        D Offline
        David Demelier
        wrote on 17 Sept 2018, 15:40 last edited by
        #3

        Thank you very much, that indeed did the trick :)

        1 Reply Last reply
        0

        1/3

        13 Sept 2018, 14:57

        • Login

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