我Canvas在 QML 中使用 OpenGL 来绘制旋转Rectangle。这是代码:
//...
property variant points: []
onPointsChanged:{
canvas.requestPaint();
}
//...
Canvas{
//...
onPaint:{
var ctx = canvas.getContext('2d')
ctx.clearRect(0,0, width, height);
ctx.beginPath()
ctx.strokeStyle = 'red'
ctx.lineWidth = 3
for(var i = 0; i < points.length; i++){
var p1 = convertPoint(points[i])
if(i == 0){
ctx.moveTo(p1.x, p1.y)
continue
}
ctx.lineTo(p1.x, p1.y)
}
ctx.stroke()
ctx.restore()
}
function convertPoint(p){
var x = p.x * width;
var y = p.y * height;
return Qt.point(x,y);
}
}
Run Code Online (Sandbox Code Playgroud)
C++代码中计算了4个点,每30ms发送到qml。问题是,在 MinGW …