Table of Contents

Layout basics

Element

Item

item-example.qml
import QtQuick 1.0
 
Item {
   width: 100
   height: 100
}
Item {
   width: 100; height: 100
}

Rectangle

rectangle-example.qml
import QtQuick 1.0
 
Rectangle {
   width: 100
   height: 100
   color: "red"
   border.color: "black"
   border.width: 5
   radius: 10
}

Nesting Items

item-nested-example.qml
import QtQuick 1.0 
 
Item {
   width: 100
   height: 100
 
   Rectangle {
      anchors.fill: parent
      color: "red"
      border.color: "black"
      border.width: 5
      radius: 10
   }
}

Image

image-example-abs.qml
import QtQuick 1.0
 
Item {
   width: 300
   height: 300
 
   Image {
       x: 30
       y: 40
       source:"images/spaceship.png"
   }
}
image-example.qml
import QtQuick 1.0
 
Item {
   width: 300
   height: 300
 
   Image {
       anchors.horizontalCenter: parent.horizontalCenter
       anchors.verticalCenter: parent.verticalCenter
       source:"images/spaceship.png"
   }
}

Text and TextInput

text-example.qml
import QtQuick 1.0 
 
Item {
   width: 100
   height: 100
 
   Text {
      text: "Hello World!"
      font.family: "Helvetica"
      font.pixelSize: 14
      color: "blue"
      x: 0
      y: 0
   }
}
textinput-example.qml
import QtQuick 1.0 
 
Item {
   width: 200
   height: 100
 
   Text {
      text: "Enter your name:"
      font.family: "Helvetica"
      font.pixelSize: 14
      color: "blue"
      x: 0
      y: 0
   }
 
   TextInput {
      text: "Default Text"
      font.family: "Helvetica"
      font.pixelSize: 14
      color: "red"
      x: 10
      y: 20
      focus: true
   }
}

Naming things

...
   Text {
      id: myMessage
      text: "Hello World!"
      font.family: "Helvetica"
      font.pixelSize: 14
      color: "blue"
      x: 0
      y: 0
   }
 
   Image {
       id: spaceshipImage
       anchors.horizontalCenter: parent.horizontalCenter
       anchors.verticalCenter: parent.verticalCenter
       source:"images/spaceship.png"
   }
...

Resources