【发布时间】:2016-07-04 20:20:35
【问题描述】:
在 QML StackView docs 中提到您可以使用以下属性推送item:stackView.push({item: someItem, properties: {fgcolor: "red", bgcolor: "blue"}})
有没有一种方法可以通过属性推送component?我的组件基本上是其他 .qml 文件的包装器,用于我的应用程序的不同视图,例如:
Component{
id: loginComponent
Login{}//The Login.qml file of my project
}
这就是我正在尝试的:
Main.qml
ApplicationWindow {
id: appWindow
visible: true
width: Screen.desktopAvailableWidth
height: Screen.desktopAvailableHeight
property alias stackv: stackv
property alias loginComponent: loginCom
StackView {
id: stackv
anchors.top: topHeader.bottom
anchors.topMargin: 10
anchors.bottom: parent.bottom
width: parent.width
focus: true
Component {
id: loginCom
Login {
anchors.fill: parent
}
}
}
}
在另一个 QML 文件中,它作为组件推送到 stackview,我正在按钮的 onClick 方法之一上尝试:
onClicked: {
appWindow.stackv.push({item: appWindow.loginComponent})
}
我被这个错误弹出:
QML StackView:推送:没有什么可推送的
如果我在没有 item 属性的情况下尝试这个,它会起作用。但是,无论哪种方式,我都无法推送属性。
【问题讨论】:
标签: qt qml qtquickcontrols