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在调用函数时候找不到函数,提示函数未定义。
此篇博客介绍了如何在图片组件中根据C++模型传递的字符串参数动态设置图片源,通过seletImg函数实现不同文件类型的图标选择,如视频、语音和图片。函数设计确保了与模型数据的无缝对接。
4446

被折叠的 条评论
为什么被折叠?



