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. Center all Items to the middle of the screen
Forum Updated to NodeBB v4.3 + New Features

Center all Items to the middle of the screen

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 1.2k Views 3 Watching
  • 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.
  • U Offline
    U Offline
    ubik
    wrote on last edited by SGaist
    #1

    Helo,

    My Code is the following:

    Grid {
                id: myGrid
                rows: 4
                columns: 1
                width: parent.width
                height: partent.height
                spacing: 50
                anchors.horizontalCenter: parent.horizontalCenter
    
    
    
                Image {
                         id: circleImage
                         source: "circle.png"
                          // the CircleCollider has its origin in the center, not top-left
                         anchors.horizontalCenter: parent.horizontalCenter
                         Text { anchors.centerIn: parent
                                font.pointSize: 48; text: accelerometer.steps }
                }
    
                Label {
                    id: labelSteps
                    text: "Schritte"
    
                    anchors.horizontalCenter: circleImage.horizontalCenter
                    anchors.top: circleImage.bottom
                    anchors.topMargin: 5
                }
    
                Image {
                         id: circleImage2
                         source: "circle2.png"
                         anchors.horizontalCenter: labelSteps.horizontalCenter
                         anchors.top: labelSteps.bottom
                         anchors.topMargin: 40
                         Text { anchors.centerIn: parent
                         font.pointSize: 48; text: accelerometer.distance}
                }
    
                Label {
                    id: labelDistance
                    anchors.horizontalCenter: circleImage2.horizontalCenter
                    anchors.top: circleImage2.bottom
                    anchors.topMargin: 5
                    anchors { bottom: circleImage2.bottom; horizontalCenter: circleImage2.horizontalCenter }
                    text: "km"
                }
    }
    

    It should look like that:

    http://fs1.directupload.net/images/150818/qiufx8st.png

    But it looks like that:

    http://www.bilder-upload.eu/show.php?file=31e598-1439891706.png

    How can I center all Items to the middle of the screen?

    [edit: Added missing coding tags ``` SGaist]

    C 1 Reply Last reply
    0
    • C Offline
      C Offline
      charlycoste
      wrote on last edited by
      #2

      In my humble opinion, you should probably better post this question to the Qt Quick section as it is a question about QML.

      "It's not because things are difficult that we dare not venture. It's because we dare not venture that they are difficult." - Lucius Annaeus Seneca

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Moved, no need to duplicate posts

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • U ubik

          Helo,

          My Code is the following:

          Grid {
                      id: myGrid
                      rows: 4
                      columns: 1
                      width: parent.width
                      height: partent.height
                      spacing: 50
                      anchors.horizontalCenter: parent.horizontalCenter
          
          
          
                      Image {
                               id: circleImage
                               source: "circle.png"
                                // the CircleCollider has its origin in the center, not top-left
                               anchors.horizontalCenter: parent.horizontalCenter
                               Text { anchors.centerIn: parent
                                      font.pointSize: 48; text: accelerometer.steps }
                      }
          
                      Label {
                          id: labelSteps
                          text: "Schritte"
          
                          anchors.horizontalCenter: circleImage.horizontalCenter
                          anchors.top: circleImage.bottom
                          anchors.topMargin: 5
                      }
          
                      Image {
                               id: circleImage2
                               source: "circle2.png"
                               anchors.horizontalCenter: labelSteps.horizontalCenter
                               anchors.top: labelSteps.bottom
                               anchors.topMargin: 40
                               Text { anchors.centerIn: parent
                               font.pointSize: 48; text: accelerometer.distance}
                      }
          
                      Label {
                          id: labelDistance
                          anchors.horizontalCenter: circleImage2.horizontalCenter
                          anchors.top: circleImage2.bottom
                          anchors.topMargin: 5
                          anchors { bottom: circleImage2.bottom; horizontalCenter: circleImage2.horizontalCenter }
                          text: "km"
                      }
          }
          

          It should look like that:

          http://fs1.directupload.net/images/150818/qiufx8st.png

          But it looks like that:

          http://www.bilder-upload.eu/show.php?file=31e598-1439891706.png

          How can I center all Items to the middle of the screen?

          [edit: Added missing coding tags ``` SGaist]

          C Offline
          C Offline
          charlycoste
          wrote on last edited by charlycoste
          #4

          @ubik said:

          It should look like that:

          http://fs1.directupload.net/images/150818/qiufx8st.png

          But it looks like that:

          http://www.bilder-upload.eu/show.php?file=31e598-1439891706.png

          How can I center all Items to the middle of the screen?

          Actually, as the first picture is really schematic, I don't even understand what is the difference between what you want and what you get...

          If you want it to be horizontally centered, it's seems good for me, by the way.
          If you want it to be vertically centered, I don't understand why you didn't just add anchors.verticalCenter after anchors.horizontalCenter in your Grid element :

          Grid {
              id: myGrid
              rows: 4
              columns: 1
              width: parent.width
              height: partent.height
              spacing: 50
              anchors.horizontalCenter: parent.horizontalCenter
              anchors.verticalCenter: parent.verticalCenter
              ...
          

          "It's not because things are difficult that we dare not venture. It's because we dare not venture that they are difficult." - Lucius Annaeus Seneca

          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