返回方法Sailfish应用开发入门(五)PageStack、Button使用
最近研究返回方法,稍微总结一下,以后继续补充:
PageStack供提了基于栈的Sailfish UI航导模型。
PageStack由多个page面页构成,一个面页可以push到栈面里代替栈顶的page,或者从栈里移除某个page。
Sailfish 应用被创立的时候PageStack就经已包含了一个page,这个page是由ApplicationWindow initialPage属性指定的。
PageStack属性:
busy:bool 当PageStack正在进行push或pop的时候为true
currentPage:item PageStack栈顶page
depth: int PageStack以后有多少个page
PageStack方法:
PageStack:clear() 从栈里移除有所page
PageStack:find(function) 从栈顶到底栈搜索page,晓得碰到function返回true的时候。function必须是一个js方法对象,收接page参数并且返回true或者false。
PageStack:openDialog(dialog, properties, immediate) 压入一个Dialog到栈面里
PageStack::pop(page, immediate) 从栈里移除page,如果没有传入page参数,则移除以后page。
PageStack::push(page, properties, immediate) 向栈里压入一个page。page可所以Item、Component、qml的url或page数组。
PageStack::replace(page, properties, immediate)
PageStack::replaceWithDialog (dialog, properties, immediate)
//main.qml
import QtQuick 1.1
import Sailfish.Silica 1.0
import "pages"
ApplicationWindow
{
initialPage: Page {
id: page
Item {
id: item
anchors.centerIn: parent
Button {
id: btn1
text: "Button1"
onClicked: pageStack.push(Qt.resolvedUrl("pages/FirstPage.qml"))
}
Button {
id: btn2
anchors.baseline: btn1.bottom
text: "Button2"
onClicked: pageStack.push(Qt.resolvedUrl("pages/SecondPage.qml"))
}
}
}
cover: Qt.resolvedUrl("cover/CoverPage.qml")
}
//FirstPage.qml
import QtQuick 1.1
import Sailfish.Silica 1.0
Page {
id: page
Button {
anchors.horizontalCenter: page.horizontalCenter
anchors.baseline: page.baseline
text: "Back"
onClicked: pageStack.pop()
}
Label {
anchors.centerIn: parent
text: "This is FirstPage"
}
}
//SecondPage.qml
import QtQuick 1.1
import Sailfish.Silica 1.0
Page {
id: page
Button {
anchors.horizontalCenter: page.horizontalCenter
anchors.baseline: page.baseline
text: "Back"
onClicked: pageStack.pop()
}
Label {
anchors.centerIn: parent
text: "This is SecondPage"
}
}
文章结束给大家分享下程序员的一些笑话语录:
自从有了Photoshop,我再也不相信照片了!(没有Photoshop的年代,胶片照片年代做假的也不少,那时候都相信假的!)

浙公网安备 33010602011771号