[Solved] QML delegate Component for TableColumnView



  • Hi,

    I have following code. The commented line works well enough as a delegate, but when I try to make a component as a delegate I get errors (line below the commented one. Is there any way to pass on parameters to a delegate? I tried using projName instead of "something", but that gave a reference error.

    Best regards and thanks

    Jos

    @Rectangle {
    ListModel {
    id: permissionsModel
    Component.onCompleted: {
    append({"projName": qsTr("Main Project"), "folder": true, "permissions_version": "2.0", "guest": true, "regular": false, "contractor": true, "service": true})
    append({"projName": qsTr("Databases"), "folder": false, "permissions_version": "2.0", "guest": false, "regular": true, "contractor": false, "service": false})
    append({"projName": qsTr("Libraries"), "folder": false, "permissions_version": "2.0", "guest": true, "regular": false, "contractor": true, "service": false})
    }
    }

    Component {
        id: projNameDelegate
        Rectangle {
            width: parent.width; height: 50
            border {color: "#9EDDF2"; width: 2}
            Text{
                anchors.centerIn: parent                
                text: "something"
                color: "#FF0000"
            }
        }
    }
    
    TableView {
        id: permissionsTable
        alternatingRowColors: true
        model: permissionsModel
    

    // TableViewColumn {role: "projName"; title: "Name" ; width: 134; delegate: Component {Rectangle{border {color: "#9EDDF2"; width: 2} Text {text: styleData.value; color: "#FF0000"}}}}
    TableViewColumn {role: "projName"; title: "Name" ; width: 134; delegate: projNameDelegate {Rectangle{Text {text: styleData.value}}}}
    TableViewColumn {role: "permissions_version"; title: "Version" ; width: 67}
    TableViewColumn {role: "guest" ; title: "Guest" ; width: 67; delegate: CheckBox{checked: styleData.value}}
    TableViewColumn {role: "regular" ; title: "Regular" ; width: 67; delegate: CheckBox{checked: styleData.value}}
    TableViewColumn {role: "contractor" ; title: "Contractor" ; width: 67; delegate: CheckBox{checked: styleData.value}}
    TableViewColumn {role: "service" ; title: "Service" ; width: 67; delegate: CheckBox{checked: styleData.value}}
    x: 0
    y: 0
    width: 540
    height: 100
    }
    }@



  • I believe something linke @property Component componentName: projNameDelegate@ would work. Alternatively you can just turn your component into a full fledged element by putting it into its own qml file.



  • I needed some experimenting, but I got it.

    I made a qml-file
    @// ProjectNameDelegate.qml

    import QtQuick 2.0

    Rectangle {
    width: parent.width; height: 50
    border {color: "#9EDDF2"; width: 2}
    id: projectNameDelegate
    Text{
    anchors.centerIn: parent
    color: "#FF0000"
    }
    }
    @

    And made the call

    @TableViewColumn {role: "projectName"; title: "Name" ; width: 134; delegate: ProjectNameDelegate{Text{text: styleData.value}}}@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.