我试图在qml-javascript中动态创建对象.创建对象的函数是:
function createSpriteObjects(xPos,yPos,cnt,imgsrc,jsonObject) {
var title;
title = jsonObject.matches[cnt].recipeName;
var component = Qt.createComponent("FlickItem.qml");
component.createObject(wall.contentItem, {"color":"white", "x":xPos,"y":yPos,"src":imgsrc,"opacity":1,"title":title});
}
Run Code Online (Sandbox Code Playgroud)
接收文件(FlickItem.qml)具有属性字符串标题,稍后将其分配给Text项的文本字段:
import QtQuick 2.0
Rectangle {
id: name
opacity: 0
property string title: ""
width:100
height:100
color:"white"
property string src: ""
Image {
id:recipeimages
source: src
width:240
height:160
}
Text {
id: title
anchors.bottom: recipeimages.bottom
anchors.horizontalCenter: recipeimages.horizontalCenter
anchors.bottomMargin: 5
color: "white"
font.pixelSize: 24
text:title
}
Run Code Online (Sandbox Code Playgroud)
返回以下错误:
无法将QQuickText分配给QString
有什么方法吗?
我正在尝试使用canvas API(与html5中使用的相同)在qml中创建一个计时器.我需要每隔一秒左右重绘一次屏幕.是否有任何功能可以用新馈送的参数更新屏幕?例如,我使用弧函数,我指定绘制时钟弧的角度:
ctx.arc(150, 150, 95, 0,1.57,false);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,角度会每隔一秒左右变化一次.