一個Item對應一個場景,提供隱藏或顯示場景即可切換,如下:
import QtQuick 2.2
import QtQuick.Controls 1.1
ApplicationWindow
{
visible: true
width: 480
height: 360
title: "Hello World"
Item
{
id: scene_1
visible: true
anchors.fill: parent
Text
{
anchors.centerIn: parent
textFormat: Text.RichText
text: "<h1><font color=red>這是第一個場景</color></h1>"
}
MouseArea
{
anchors.fill: parent
onClicked:
{
scene_1.visible = false;
scene_2.visible = true;
scene_3.visible = false;
}
}
}
Item
{
id: scene_2
visible: false
anchors.fill: parent
Text
{
anchors.centerIn: parent
textFormat: Text.RichText
text: "<h1><font color=green>這是第二個場景</color></h1>"
}
MouseArea
{
anchors.fill: parent
onClicked:
{
scene_2.visible = false;
scene_1.visible = false;
scene_3.visible = true;
}
}
}
Item
{
id: scene_3
visible: false
anchors.fill: parent
Text
{
anchors.centerIn: parent
textFormat: Text.RichText
text: "<h1><font color=black>這是第三個場景</color></h1>"
}
MouseArea
{
anchors.fill: parent
onClicked:
{
scene_1.visible = true
scene_2.visible = false;
scene_3.visible = false;
}
}
}
}