Text {
id: imgSource
text: translation.qsTr(type)
visible: false
}
Rectangle{//左上角的文件类型图标
width: 16
height: 16
anchors.top: parent.top
anchors.left: parent.left
color: Qt.rgba(0,0,0,0.5)
visible: sourceType.source == "" ? false : true
clip: true
Image {
id: sourceType
anchors.centerIn: parent
source: seletImg(imgSource.text)
function seletImg(imgChoiceText){
console.log("===========================1111111111111111111" + imgChoiceText)
if(imgChoiceText === "Videos" || imgChoiceText === "GIF"){//视频图标
sourceType.source = "qrc:/image/materials/videoLogo.svg"
}else if(imgChoiceText === "Voice"){
sourceType.source = "qrc:/image/materials/voiceLogo.svg"
}else if(imgChoiceText === "Image"){
sourceType.source = ""
}
}
}
}
我要在图片中对他的source使用函数来确定图片的源文件路径,这个函数传入的参数是c++model给我传来的字符串。函数必须要写在image里面他才能调用到,否则image在调用函数时候找不到函数,提示函数未定义。