Home > front end >  Qt6 ConicalGradient
Qt6 ConicalGradient

Time:09-04

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. I also need to import both modules in qml, so how can I specify the one from QtQuick.Shapes shall be used?

CodePudding user response:

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 }
        }
    }
}
  • Related