QML画三角形代码

2019-07-15 15:06:52 浏览数 (1)

源代码

代码语言: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
}

0 人点赞