我正在尝试创建一个 QML 对象,它就像其他对象的包装器一样。这是我的 QML 文件(Container.qml):
Item {
property string label
property Item control
Row {
Label {
text: label
}
// Not sure how to display the control assigned to the control property
}
}
我想做的(在我使用这个组件的 QML 中)是这样的:
Container {
label: "My Label"
control: Textbox {
text: "My Value"
}
}
当输入该 QML 时,结果(在界面中)应该类似于此 QML 的输出:
Item {
Row {
Label {
text: "My Label"
}
Textbox {
text: "My Value"
}
}
}
这可能吗?当我尝试这样做时,在将项目分配给控件属性时,我得到“无法将对象分配给属性”。我搜索了 Qt 论坛并无情地用谷歌搜索,但没有成功。如果有人知道答案,将不胜感激。
谢谢
杰克