如何画一条末端褪色的线?

问题描述 投票:0回答:1

我正在尝试在 QML 中画一条末端褪色的线,类似于此:

我尝试使用矩形绘制线条,但我不知道如何淡出末端。

我使用的是Qt 5.12。

qt qml line fade rectangles
1个回答
4
投票

您可以将矩形项目与渐变一起使用,例如:

    Rectangle {
        anchors.fill: parent
        color: "black"

        Rectangle {
            anchors.centerIn: parent
            width: 400
            height: 5
            border.width: 0
            gradient: Gradient {
                orientation: Gradient.Horizontal
                GradientStop { position: 0.0; color: "black" }
                GradientStop { position: 0.25; color: "white" }
                GradientStop { position: 0.75; color: "white" }
                GradientStop { position: 1.0; color: "black" }
            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.