Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to define QML gradient object in javascript



  • This is my qtquick qml code

    function show_me(element) {
        console.log(element.gradient)
    }
    
    
    Rectangle {
        gradient: Gradient {
            GradientStop {
                position: 0
                color: "#30cfd0"
            }
    
        GradientStop {
            position: 1
            color: "#330867"
        }
    }
    
        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
    
            onEntered: {
                show_me(parent)
            }
        }
    }
    

    The output is

    qml: QQuickGradient(0x559f18a4dd40)
    

    the output gives me a QtQuickGradient object

    I wonder how do I define a QtQuickGradient object in javascript?

    I want to do something like:

    var gradient = //QtQuickGradient (i don't know)
    element.gradient = gradient
    

    Please help me to define it




Log in to reply