TreeView - 如何使用角色作为图像源

TreeView - how to use the role as an image source

我有一个具有定义角色的简单树视图模型。 这是一个代码:

TreeView {
        model: theModel
        itemDelegate: Rectangle {
            color: ( styleData.row % 2 == 0 ) ? "white" : "lightblue"
            height: 20
            Text {
                text: styleData.value === undefined ? "" : styleData.value
            }
        }
        TableViewColumn {
            width: 100
            role: "name_role"
            title: "Map"
        }
        TableViewColumn {
            width: 50
            role: "description_role"
            title: "Description"
        }

        Image {
            width: 15
            source: description_role + ".png"
            }

    }

在第二栏中我显示了正确的描述,但是当我使用这个角色作为图片来源时我犯了错误"role is undefined"。

问题是:如何正确定义角色为图片来源?

我通过阅读 TableViewColumn 的文档找到了答案 QML treeView 应该是这样的:

TreeView {
    model: theModel
    itemDelegate: Rectangle {
        color: ( styleData.row % 2 == 0 ) ? "white" : "lightblue"
        height: 20
        Text {
            text: styleData.value === undefined ? "" : styleData.value
        }
    }
    TableViewColumn {
        width: 100
        role: "name_role"
        title: "Map"
    }
    TableViewColumn {
        width: 50
        role: "description_role"
        title: "Description"
    }
    TableViewColumn {
        width: 50
        role: "description_role"
        title: "Icon"
        delegate: Image {
            source: styleData.value + ".png"
            }
        }

}