QML 页面切换,比如直播应用,从登录页跳转到视频页。
静态:
一,隐藏
本质上各页面都存在,只是某些隐藏,某些显示,当某一触发条件满足时,设置对应页面的显示和隐藏
Rectangle{
id:login
width: 500
height: 500
MouseArea{
anchors.fill: parent
onClicked: {
video.visible=true
login.visible=false
}
}
}
Rectangle{
id:video
width: 500
height: 500
visible: false
}
二,利用 StackView、SwipeView
动态:
一,利用Loader 动态加载
function showLoginPage()
{
myLoader.sourceComponent=loginPage
}
function showVideoPage()
{
myLoader.sourceComponent=videoPage
}
Loader{
id:myLoader
anchors.fill: parent
}
Component.onCompleted: showLoginPage()
Component{
id:loginPage
Login{
anchors.fill: parent
}
}
Component{
id:videoPage
Video{
anchors.fill: parent
}
}
二,利用 createComponent 创建
var component = Qt.createComponent("SubmitDia.qml")
var object = component.createObject(root)
object.x = root.width/2-object.width/2
object.y = root.height/2-object.height/2
场景:
如果想记录上一次的操作 可以使用静态的方式,比如设置,切换到下一页 但也可能返回到上一页。
如果想每次进入页面时,一切从新开始 不想记录任何信息,则使用动态方式。比如登录类切换,登录后一切都应该从新开始