一个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;
}
}
}
}