简体   繁体   English

Qt6锥形渐变

[英]Qt6 ConicalGradient

As I have understand there is a ConicalGradient in Qt5Compat.GraphicalEffects and there is one in QtQuick.Shapes .I want to fill a Shape with Gradient in Qt6 but there is an Error with property names.据我了解,Qt5Compat.GraphicalEffects 中有一个ConicalGradientQtQuick.Shapes中有一个。我想在Qt6中用Gradient填充一个Shape ,但属性名称有一个错误。 I also need to import both modules in qml, so how can I specify the one from QtQuick.Shapes shall be used?我还需要在 qml 中导入两个模块,那么如何指定 QtQuick.Shapes 中的一个应该使用?

https://doc.qt.io/qt-6/qtqml-syntax-imports.html#importing-into-a-qualified-local-namespace https://doc.qt.io/qt-6/qtqml-syntax-imports.html#importing-into-a-qualified-local-namespace

import QtQuick
import QtQuick.Shapes
import Qt5Compat.GraphicalEffects as GE

Window {
    width: 640
    height: 480
    visible: true
    color: "white"
    title: qsTr("ConicalGradient")

    Item {
        width: 300
        height: 300

        GE.ConicalGradient {
            anchors.fill: parent
            angle: 0.0
            gradient: Gradient {
                GradientStop { position: 0.0; color: "white" }
                GradientStop { position: 1.0; color: "black" }
            }
        }
    }

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

        ShapePath {
            strokeWidth: 0
            strokeColor: "transparent"
            fillGradient: ConicalGradient {
                angle: 0.0
                centerX: 100
                centerY: 75
                GradientStop { position: 0; color: "blue" }
                GradientStop { position: 0.2; color: "green" }
                GradientStop { position: 0.4; color: "red" }
                GradientStop { position: 0.6; color: "yellow" }
                GradientStop { position: 1; color: "cyan" }
            }
            startX: 20
            startY: 20
            PathLine { x: 180; y: 130 }
            PathLine { x: 20; y: 130 }
            PathLine { x: 20; y: 20 }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM