Qml 在实例化时将参数传递给组件
我正在运行时创建Qml 在实例化时将参数传递给组件,qml,components,qtquick2,Qml,Components,Qtquick2,我正在运行时创建TableViewColumns,需要将角色传递给TableViewColumns TableView { model: myModel onModelChanged: { var roleList = myModel.customRoleNames for ( var i = 0; i < roleList.length; ++i ) { var role = roleList[ i ]
TableViewColumns
,需要将角色
传递给TableViewColumns
TableView {
model: myModel
onModelChanged: {
var roleList = myModel.customRoleNames
for ( var i = 0; i < roleList.length; ++i ) {
var role = roleList[ i ]
addColumn( /* my column component here */ )
}
}
}
Component {
id: columnComponent
TableViewColumn {
role: /* ??? */
}
}
TableView{
型号:myModel
在模型更改时:{
var roleList=myModel.customRoleNames
对于(变量i=0;i
在实例化组件时,如何将
角色
馈送到组件?好的,我已经找到了。以下是解决方案:
TableView {
id: myTableView
model: myModel
onModelChanged: {
var roleList = myModel.customRoleNames
for ( var i = 0; i < roleList.length; ++i ) {
var role = roleList[ i ]
addColumn( columnComponent.createObject ( myTableView, { "role": role } ) )
}
}
}
Component {
id: columnComponent
TableViewColumn { }
}
addColumn( columnComponent.createObject ( myTableView, { "role": myRole, "title": someTitle } ) )