【发布时间】:2018-08-09 07:36:46
【问题描述】:
我想将组件动态添加到 TabView/Tab 中的 ColumnLayout。但我还没有找到这样做的可能性。问题是我对 createObject 调用的 ColumnLayout 没有正确的父引用。 因为 Tab 动态加载了一个组件,所以我将 ColumnLayout 封装在一个组件中。
在 QML 调试器中,我可以解决以下路径:objForm.tabView.tabStatus.tabStatusLoader.colLayout,但我不能将其用作正确的父级。
好像不在范围内。
TypeError: Cannot read property 'tabStatus' of undefined
ObjForm.ui.qml
Item {
id: item1
width: 400
height: 400
property QtObject object
property Component compLayout
TabView {
id: tabView
anchors.fill: parent
Tab {
id: tabStatus
title: "status"
Loader {
id: tabStatusLoader
sourceComponent: compLayout
}
}
}
}
ObjForm.qml
ObjectViewForm {
id: objForm
anchors.fill: parent
object: someObj
compLayout: Component {
id: layoutComp
ColumnLayout {
id: colLayout
spacing: 2
}
}
onObjectChanged: {
// Here i want to add the someLabel Component to the ColumnLayout
someLabel.createObject(*PARENT*)
}
Component {
id: someLabel
Row {
property string text
property string label
spacing: 5
Label {
text: parent.label
}
Label {
text: parent.text
}
}
}
有谁知道如何解决这个问题或可以提出更好的建议?
【问题讨论】:
标签: qt tabs qml components tabview