基本代码如下:
import QtQuick 2.2
import QtQuick.Controls 1.1
Image
{
id: root
source: "background.png"
}
这个是使用给定图形填充背景,
如果使用多个图形嵌套,做法如下:
import QtQuick 2.2
import QtQuick.Controls 1.1
Image
{
id: root
source: "background.png"
Image
{
id: head
source: "head.png"
anchors.centerIn: parent
anchors.verticalCenterOffset: 20
}
}
当然可以再加上旋转
import QtQuick 2.2
import QtQuick.Controls 1.1
Image
{
id: root
source: "background.png"
Image
{
id: head
width: 48
height: 48
source: "head.png"
anchors.centerIn: parent
anchors.verticalCenterOffset: 20
MouseArea
{
anchors.fill: parent
onClicked: head.rotation += 9
}
}
}
加上动画可以让旋转更加平滑点,如下:
import QtQuick 2.2
import QtQuick.Controls 1.1
Image
{
id: root
source: "background.png"
Image
{
id: head
width: 48
height: 48
source: "head.png"
anchors.centerIn: parent
anchors.verticalCenterOffset: 20
MouseArea
{
anchors.fill: parent
onClicked: head.rotation += 90
}
Behavior on rotation
{
NumberAnimation
{
duration: 600
}
}
}
}