我正在尝试根据按下按钮动态加载不同的图像。
Rectangle {
id: rect
width: 800
height: 600
color: "black"
x: 300
y: 10
MediaPlayer {
id: mediaplayer
source: "images/video10.avi"
autoPlay: true
onError: videoPage1.sendToPost(mediaplayer.errorString)
}
VideoOutput {
id: videoOutput
anchors.fill: parent
source: mediaplayer
fillMode: VideoOutput.Stretch
}
MouseArea {
id: playArea
anchors.fill: parent
onPressed: {
if(!mediaplayer.hasVideo){
console.log("No media");
}
pressX = mouse.x
pressY = mouse.y
}
onReleased: {
releaseX = mouse.x
releaseY = mouse.y
doSomething();
roi_flag=0;
}
}
}
Component {
id: highlightComponent;
Rectangle {
color: "transparent";
border.color: "black"
border.width: 2
property alias text:t1.text;
property alias ss: image.source;
Text {
id: t1
text: "click"
anchors.centerIn: parent
width: 5
}
Image {
id:image
// width: 130; height: 100
// source: (direction_flag ? "images/top.png" : "images/right.png")
source : ss
anchors.centerIn: parent
}
}
}
function doSomething(){
console.log(rOI);
count++;
var obj = 'highlightItem' + count;
var dir;
if(direction_flag == 0){
if((pressX - releaseX) > 0){
dir= "images/left.png";
}else if((pressX - releaseX) < 0){
dir="images/right.png";
}
}else{
if((pressY - releaseY) > 0){
dir="images/top.png";
}else if((pressY - releaseY) < 0){
dir="images/down.png";
}
}
highlightComponent.incubateObject (rect, {
"x" : pressX,"y":pressY,width:releaseX - pressX,height: releaseY - pressY,text:count,ss:dir});
}
该方法在更改文本时有效,但在更改图像时无效,我收到错误“QML Image:Protocol”“未知”。
任何建议都会有所帮助,谢谢。