Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt TreeView-如何将角色用作图像源_Qt_Treeview_Qml - Fatal编程技术网

Qt TreeView-如何将角色用作图像源

Qt TreeView-如何将角色用作图像源,qt,treeview,qml,Qt,Treeview,Qml,我有一个定义了角色的简单treeview模型。 下面是一个代码: TreeView { model: theModel itemDelegate: Rectangle { color: ( styleData.row % 2 == 0 ) ? "white" : "lightblue" height: 20 Text { text: styleData.valu

我有一个定义了角色的简单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"
        }

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

    }
在第二列中,我显示了正确的描述,但当我将此角色用作图像源时,我出现了错误“角色未定义”


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

我通过阅读TableViewColumn的文档找到了答案 QML树视图应如下所示:

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

}

图像
对象与
项目委托
无关,因此您希望在哪里绘制它?它将在树状视图中绘制,就像列一样。ItemDelegate仅描述单元格的视图。无论如何,将图像放在itemdelegate中不会改变任何事情-静态角色未定义。