我有多个QML文件.我只是想把它们联系起来.然后我想从我浏览的每个页面返回到我的主页.我在每个页面都使用加载器这是我的代码.
import QtQuick 1.1
Rectangle{
id:welcome
width:480
height:272
Loader{
id:loader
focus:false
anchors.fill: parent
}
gradient: Gradient {
GradientStop { position: 0.0; color: "light blue" }
GradientStop { position: 1.0; color: "blue" }
}
Text{
text:"\n\t\tPRESS ENTER"
font.bold:true
font.pointSize: 17
}
Button {
id: wel
height:30;
x:parent.width/2-30
y:parent.height/2-30
focus:true
border.color:"black"
opacity: activeFocus ? 1.0 : 0.5
Text{
text:"WELCOME"
anchors.horizontalCenter:wel.horizontalCenter;
anchors.verticalCenter:wel.verticalCenter;
}
Keys.onReturnPressed: {
wel.focus=false
loader.focus=true;
anchors.fill=parent
loader.source="Home.qml";
//welcome.visible=false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是每当我点击按钮加载新文件.但是欢迎页面不会出现.两个文件都将重叠.当我做了visible = false时,完整的UI将会出现.我得到一个白色的屏幕.任何人都可以帮我解决这个问题吗?如何加载其他文件?
要加载多个页面,您需要使用Connections元素处理来自已加载页面的信号.
Loader {
id: windowLoader
source: "Welcome.qml"
focus: true
property bool valid: item !== null
}
Button {
Keys.onReturnPressed: {
windowLoader.source = "Page1.qml"
}
}
Connections {
ignoreUnknownSignals: true
target: windowLoader.valid? windowLoader.item : null
onChangeToPage2: { windowLoader.source = "Page2.qml" }
onPageExit: { windowLoader.source = "Welcome.qml" }
}
Run Code Online (Sandbox Code Playgroud)
从您加载的页面中,您将需要发出"changeToPage2"和"pageExit" 信号.发出的信号将由Connections元素处理.
Page1.qml:
Rectangle {
id: page1
signal changeToPage2
signal pageExit
Button {
id: exitButton
Keys.onReturnPressed: { page1.pageExit() }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15263 次 |
| 最近记录: |