Aka*_*wal 1 qt qml qtquickcontrols
在QML StackView 文档中,提到您可以item使用以下属性进行推送:
stackView.push({item: someItem, properties: {fgcolor: "red", bgcolor: "blue"}})
有没有办法可以用属性推动component?我的组件基本上.qml是我的应用程序的不同视图的其他文件的包装器,例如:
Component{
id: loginComponent
Login{}//The Login.qml file of my project
}
Run Code Online (Sandbox Code Playgroud)
这就是我正在尝试的:
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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在另一个QML文件中,它作为组件被推送到stackview,我正在尝试使用按钮的onClick方法之一:
onClicked: {
appWindow.stackv.push({item: appWindow.loginComponent})
}
Run Code Online (Sandbox Code Playgroud)
我遇到这个错误:
QML StackView:推送:无需推送
如果我在没有item财产的情况下尝试这个,它就有效.但是,无论哪种方式,我都无法推动属性.
推送到StackView的项目可以是Item,URL,包含URL的字符串或Component.
所以只需传递一个组件:
stackView.push({item: loginComponent, properties: {/*...*/}})
Run Code Online (Sandbox Code Playgroud)
编辑:事实证明,在您编辑问题并添加警告输出后,您实际上正在使用Qt Quick Controls 2中的StackView,而不是来自文档链接所指向的Qt Quick Controls 1.
stackView.push(loginComponent, {/*...*/})| 归档时间: |
|
| 查看次数: |
4452 次 |
| 最近记录: |