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
QtWS25 Last Chance

Center all Items to the middle of the screen

Scheduled Pinned Locked Moved QML and Qt Quick
centerlayout
8 Posts 2 Posters 2.5k 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.
  • U Offline
    U Offline
    ubik
    wrote on 18 Aug 2015, 15:47 last edited by
    #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?

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on 18 Aug 2015, 15:53 last edited by
      #2

      anchors.verticalCenter: parent.verticalCenter? Or anchors.centerIn: parent?

      U 1 Reply Last reply 18 Aug 2015, 18:24
      0
      • X xargs1
        18 Aug 2015, 15:53

        anchors.verticalCenter: parent.verticalCenter? Or anchors.centerIn: parent?

        U Offline
        U Offline
        ubik
        wrote on 18 Aug 2015, 18:24 last edited by ubik
        #3

        @xargs1

        Where to put it? When i put

        anchors.verticalCenter: parent.verticalCenter

        in Grid, then i get this:

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

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xargs1
          wrote on 18 Aug 2015, 18:31 last edited by
          #4

          What is the height of the parent? If the parent's height is greater than the screen size, verticalCenter won't work.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            ubik
            wrote on 19 Aug 2015, 06:28 last edited by
            #5

            The height of the parent isn't set.

            Well, when I put "anchors.verticalCenter: parent.verticalCenter" in the grid, it does center vertically the first image. But the other elements are just moving down under the first image.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xargs1
              wrote on 19 Aug 2015, 06:32 last edited by
              #6

              I don't think you can center in something that doesn't have a height.

              U 1 Reply Last reply 19 Aug 2015, 07:10
              0
              • X xargs1
                19 Aug 2015, 06:32

                I don't think you can center in something that doesn't have a height.

                U Offline
                U Offline
                ubik
                wrote on 19 Aug 2015, 07:10 last edited by
                #7

                @xargs1

                So, how to set width and height with the screen size?

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xargs1
                  wrote on 19 Aug 2015, 16:25 last edited by
                  #8

                  You can reference Screen.width and Screen.height.

                  1 Reply Last reply
                  0

                  1/8

                  18 Aug 2015, 15:47

                  • Login

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