Window {
visible: true
width: 640
height: 480
Canvas{
id: canvas
width: parent.width
height: parent.height
onPaint: {
var ctx = getContext("2d");
draw(ctx);
}
function draw(ctx ) {
// 畫之前清空畫布
ctx.clearRect(0, 0, parent.width, parent.height);
ctx.fillStyle ="#F5DEB3";
ctx.fillRect(0, 0,parent.width, parent.height);
ctx.fillStyle ="#111"; // 設置畫筆屬性
ctx.strokeStyle = "#333";
ctx.lineWidth = 2
ctx.beginPath(); // 開始一條路徑
ctx.moveTo(0, 0); // 移動到指定位置
ctx.lineTo(parent.width, parent.height);
ctx.fillText("ttttt", parent.width / 2, parent.height / 2);
ctx.stroke();
}
}
}