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. Dynamically change rectangle gradient
QtWS25 Last Chance

Dynamically change rectangle gradient

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 3 Posters 1.9k Views
  • 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.
  • Q Offline
    Q Offline
    qttester5
    wrote on last edited by
    #1

    I am trying to dynamically change a Rectangle gradient, but I'm not sure the syntax. This does not work:

    @ Rectangle{
    id:tt
    width: height
    height: parent.height*1.5
    color: "black"
    anchors.centerIn: parent

            gradient: Gradient {
    
                    GradientStop { position: 0.0; color: "lightsteelblue" }
                    GradientStop {position: 1.0; color: "blue" }
                }
    
            MouseArea{
                onEntered: {
                    tt.gradient=Gradient{
                        GradientStop { position: 0.0; color: "red" }
                        GradientStop {position: 1.0; color: "yellow" }
                    }
                }
            }@
    

    This won't even compile, the onEntered contents are not proper syntax, but I'm not sure how to manipulate the gradient in there.

    Any ideas?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qttester5
      wrote on last edited by
      #2

      i managed to do this not by adjusting the gradient directly, but by making the colors property's of the rectangle and binding the gradient to those properties, and then adjusting those properties from the mouse area.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nus1998
        wrote on last edited by
        #3

        You can define a bool property supposed "overArea" in Rectangle and in the gradient use "color: overArea ? "lightsteelblue" : "red". besides that, set the property values in the MouseArea onEntered and onExited events, don't forget to set anchors.fill and hoverEnable property of MouseArea

        1 Reply Last reply
        0
        • S Offline
          S Offline
          surfsky
          wrote on last edited by
          #4

          I got the same trouble, how to dynamical adjust gradient.stops(insert/remove/clear)? I want to create a GradientColorPicker controls. tks lots

          1 Reply Last reply
          0
          • S Offline
            S Offline
            surfsky
            wrote on last edited by
            #5

            I got the same trouble, how to dynamical adjust gradient.stops(insert/remove/clear)? I want to create a GradientColorPicker controls. tks lots

            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