在实例化时将参数传递给Component

时间:2015-11-10 09:49:44

标签: qml components qtquick2

我在运行时创建TableViewColumns,需要将role传递给TableViewColumn

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: /* ??? */
    }
}

如何在实例化我的组件时将role提供给我的组件?

1 个答案:

答案 0 :(得分:1)

好的,我已经知道了。这是解决方案:

SYNTAX 1.3.6.1.4.1.1466.115.121.1.15

当然,这适用于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 { } } 的所有属性,例如:

TableViewColumn