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. QML GridLayout text align in column

QML GridLayout text align in column

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 4 Posters 8.6k 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.
  • F Offline
    F Offline
    filipdns
    wrote on last edited by
    #1

    Hello, I'm trying to have my text horizontal align inside the column but nothing work, any one know why?...

    The goal is using locale storage database when the data are displayed in the row, all column take the screen width (10 columns) and text is aligned inside the cells.

    I don't want use columnSpacing because that cause some trouble when the application is used on other computer with a different resolution...

    about text in the column, I try qt.align or anchors.horizontalCenter and many other thing but that is not working, text is always to left of the column.

    Could you help me?
    Thanks a lot

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!

      import QtQuick 2.7
      import QtQuick.Controls 2.0
      import QtQuick.Layouts 1.3
      
      ApplicationWindow {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          GridLayout {
               id: grid
               anchors.fill: parent
               columns: 3
      
               Text { text: "One";   Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter; }
               Text { text: "Two";   Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter; }
               Text { text: "Three"; Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter; }
               Text { text: "Four";  Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter; }
               Text { text: "Five";  Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter; }
               Text { text: "Six";   Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter; }
          }
      }
      
      1 Reply Last reply
      1
      • F Offline
        F Offline
        filipdns
        wrote on last edited by
        #3

        Hello thank you very much but no result... all still to the left..

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Works for me. What's your Qt version etc?

          K 1 Reply Last reply
          1
          • F Offline
            F Offline
            filipdns
            wrote on last edited by
            #5

            I'm working with QT 5.9...

            1 Reply Last reply
            0
            • F Offline
              F Offline
              filipdns
              wrote on last edited by
              #6

              here my code...```
              GridLayout {
              anchors.fill: parent

                                          columns: 10
                                          //anchors.left:parent.left
              
              
                                          Text {
                                              id: rimmatriculation
                                              text: immatriculation
                                              Layout.alignment: Qt.AlignCenter
                                              Layout.minimumWidth :100
              
                                              font.pixelSize: 22
                                              color: "black"
                                          }
              
                                          Text {
                                              id: raircrafttype
                                              text: aircrafttype
                                              Layout.alignment: Qt.AlignCenter
                                              Layout.minimumWidth :100
              
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rnumerodeserie
                                              text: numerodeserie
                                              Layout.alignment: Qt.AlignCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rdateconstruction
                                              text: dateconstruction
                                              Layout.alignment: Qt.AlignCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rpremiercertificatimmat
                                              text: premiercertificatimmat
                                              Layout.alignment: Qt.AlignCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rnumeroLSA
                                              text: numeroLSA
                                              Layout.alignment: Qt.AlignCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rdateLSA
                                              text: dateLSA
                                              Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                                              Layout.minimumWidth :100
              
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rnumerocertificatnuisance
                                              text: numerocertificatnuisance
                                              Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize:22
                                              color: "black"
                                          }
                                          Text {
                                              id: rdateCDN
                                              text: dateCDN
                                              Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                          Text {
                                              id: rdatecertificatassurance
                                              text: datecertificatassurance
                                              Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
                                              Layout.minimumWidth :100
                                              font.pixelSize: 22
                                              color: "black"
                                          }
                                      }```
              
              1 Reply Last reply
              0
              • N Offline
                N Offline
                NachoFly
                wrote on last edited by NachoFly
                #7

                Eventhough the topic is fairly old, it is still unanswered. I was struggling with the same problem and the fix that worked for me was adding

                Layout.fillWidth: true
                

                to the

                Text{}
                
                F 1 Reply Last reply
                3
                • N NachoFly

                  Eventhough the topic is fairly old, it is still unanswered. I was struggling with the same problem and the fix that worked for me was adding

                  Layout.fillWidth: true
                  

                  to the

                  Text{}
                  
                  F Offline
                  F Offline
                  filipdns
                  wrote on last edited by
                  #8

                  @NachoFly Hello, I never try that before thank a lot!!!!!

                  1 Reply Last reply
                  0
                  • ? A Former User

                    Works for me. What's your Qt version etc?

                    K Offline
                    K Offline
                    klopp
                    wrote on last edited by
                    #9

                    Qt version 5.1.1 and the rest of it should be listed. Developing this on Windows 10

                    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