Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QML delegate Component for TableColumnView
QtWS25 Last Chance

[Solved] QML delegate Component for TableColumnView

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zarkon
    wrote on last edited by
    #1

    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
    }
    }@

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zarkon
        wrote on last edited by
        #3

        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}}}@

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved