Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to define QML gradient object in javascript
Qt 6.11 is out! See what's new in the release blog

How to define QML gradient object in javascript

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 600 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 4 Offline
    4 Offline
    404omar
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      Google: "qml dynamic objects"
      https://doc.qt.io/qt-5/qtqml-javascript-dynamicobjectcreation.html

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved