源代码
代码语言:javascript复制import QtQuick 2.5
Canvas {
id: canvasId
property color triangleColor: "#474747"
width: parent.width; height: parent.height
contextType: "2d"
onPaint: {
context.lineWidth = 0
context.strokeStyle = "#00000000"
context.fillStyle = triangleColor
context.beginPath();
context.moveTo(0, 0)
context.lineTo(0, canvasId.height);
context.lineTo(canvasId.width, canvasId.height/2);
context.closePath();
context.fill()
context.stroke();
}
}
使用
width与height是控制三角形的大小
代码语言:javascript复制Triangle {
anchors.centerIn: parent
width: 100; height: 100
}