Table of Contents

Positioning elements

Absolute positioning

basic-positioners.qml
import QtQuick 1.0
 
Item {
    width: 400
    height: 400
 
    Image {
        anchors.fill: parent
        source: "images/background.png"
    }
 
    Image {
        id: spaceship
        source: "images/spaceship.png"
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
    }
}

Relative positioning

anchors-positioners.qml
import QtQuick 1.0
 
Item {
    width: 400
    height: 400
 
    Image {
        anchors.fill: parent
        source: "images/background.png"
    }
 
    Spaceship {
        id: spaceship
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
    }
}

Multiple items

more-anchors-positioners.qml
import QtQuick 1.0
 
Item {
    width: 400
    height: 400
 
    Image {
        anchors.fill: parent
        source: "images/background.png"
    }
 
    Image {
        id: spaceship
        source: "images/spaceship.png"
        anchors.verticalCenter: parent.verticalCenter
        anchors.horizontalCenter: parent.horizontalCenter
    }
 
    Image {
        id: anotherSpaceship
        source: "images/spaceship.png"
        scale: 0.5
        smooth: true
        anchors.top: spaceship.bottom
        anchors.right: spaceship.right
        anchors.rightMargin: 100
    }
}

Resources