Background for our Examples


I would like to make the next example a little bit more fancier than today. The first step is to define a background.

A background should cover all our top-level element. We changed our usual Rectangle root-element into an Item element. This gives us an element, which has a dimension, but no visual representation by itself. The Rectangle child element will do the job. It is filled across the root-element and has a dark-gray color. The Image element tiles a small image across the Rectangle used as background.

The image we use looks like this (3 x zoomed):

import Qt 4.6

Item {
    width: 200
    height: 200

    Rectangle {
        id: background
        anchors.fill: parent;
        color: "#343434"
        Image { source: "images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent;  opacity: 0.3 }
    }
}

The opacity will mix the Rectangles background with the image. Try to change the color (to “green”) and see what happens.

The result looks will look like this (does not show the qmlviewer):

To make the usage of the background easier I create a Background.qml component.

import Qt 4.6

Rectangle {
    id: background
    anchors.fill: parent;
    color: "#343434"
    Image { source: "images/stripes.png"; fillMode: Image.Tile; anchors.fill: parent;  opacity: 0.3 }
}

And use it later my examples as Background{ }.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s