C

Qt Quick Ultralite shapes Example

// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial

import QtQuick 2.15
import QtQuick.Shapes 1.0

ShapesEntry {
    id: root
    text: "Cap styles"

    Rectangle {
        color: "lightGray"
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.margins: root.contentMargins
        width: root.contentHeight
        height: root.contentHeight

        Shape {
            anchors.centerIn: parent
            width: 200
            height: 100

            scale: root.shapeScale

            ShapePath {
                id: capTest

                strokeColor: "black"
                strokeWidth: 20
                fillColor: "transparent"

                property int capStyleIdx: 0
                capStyle: style(capTest.capStyleIdx)

                startX: 50; startY: 30
                PathSvg { path: "Q 10 80 60 80 L 140 80 Q 190 80 150 30" }
            }
        }

        Text {
            anchors.top: parent.top
            anchors.right: parent.right
            anchors.margins: 2
            font.pixelSize: 10
            text: styleText(capTest.capStyleIdx)
        }
    }

    function styleText(index: int) : string
    {
        if (index == 0)
            return "FlatCap";
        else if (index == 1)
            return "SquareCap";
        else
            return "RoundCap";
    }

    function style(index: int) : ShapePath.CapStyle
    {
        if (index == 0)
            return ShapePath.FlatCap;
        else if (index == 1)
            return ShapePath.SquareCap;
        else
            return ShapePath.RoundCap;
    }

    Timer {
        interval: 1000
        repeat: true
        running: true
        onTriggered: capTest.capStyleIdx = (capTest.capStyleIdx + 1) % 3
    }
}