0

Qt6 中不存在锥形渐变,因此我想要一个圆形进度条,就像代码一样。但我无法使用锥形渐变,因为导入 QtGraphicalEffects 1.15 在 Qt6 中被废弃

这是我的代码圆锥渐变是否有另一种选择

主.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.0

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    Custom_Temp{
        anchors.centerIn: parent
        from_value: 0
        to_value: 100
        range_1: 35
        range_2: 50
        range_3: 80
        unit: "°"
        vlaue: 60
    }

}

Custom_temp.qml

import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Styles 1.4
import QtGraphicalEffects 1.15

Item {
    property int from_value
    property int to_value
    property int range_1
    property int range_2
    property int range_3
    property alias vlaue: main_progress_bar.value
    property string unit

    ProgressBar{
        anchors.centerIn: parent
        id:main_progress_bar
        from: from_value
        to: to_value
        property string actual_color: value >= range_2 ? "red": value >= range_1? "#ffe208" : "green"
        background: Rectangle {
            implicitWidth: 100
            implicitHeight: 6
            color: "transparent"
            radius: 3
        }

        contentItem:
            Rectangle{
            color: "transparent"
            implicitWidth: 100
            implicitHeight: implicitWidth
            Rectangle
            {
                id: outerRing
                z: 10
                anchors.fill: parent
                radius: Math.max(width, height) / 2
                color: "transparent"
                border.color: "gray"
                border.width: 16
            }
            Rectangle
            {
                id: innerRing
                z: 10
                anchors.fill: parent
                anchors.margins: (outerRing.border.width - border.width) / 2
                radius: outerRing.radius
                color: "transparent"
                border.color: "darkgray"
                border.width: 8

                ConicalGradient
                {
                    source: innerRing
                    anchors.fill: parent
                    gradient: Gradient
                    {
                        GradientStop { position: 0.00; color: main_progress_bar.actual_color }
                        GradientStop { position: main_progress_bar.value/100; color: main_progress_bar.actual_color }
                        GradientStop { position: (main_progress_bar.value/100) + 0.01; color: "transparent" }
                        GradientStop { position: 1.00; color: "transparent" }
                    }
                }
            }
            Label
            {
                id: progressLabel
                anchors.centerIn: parent
                color: main_progress_bar.value >= range_2? "red": main_progress_bar.value >= range_1? "#ffe208" : "green"
                text: (main_progress_bar.value.toFixed(1)) + "°"
                font.pixelSize: 20
            }
        }
    }
}

Qt6中有conicalGradient的替代品吗?

4

1 回答 1

1

Qt6中有一个ConicalGradient,但你必须使用:

import Qt5Compat.GraphicalEffects
于 2021-12-14T17:14:33.480 回答