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. Adding behavior prevents color change of rectangle

Adding behavior prevents color change of rectangle

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 337 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.
  • ocgltdO Offline
    ocgltdO Offline
    ocgltd
    wrote on last edited by
    #1

    I have a simple rectangle (below) whose color depends on a function. It works great, changing between 3 colors depending on properties of the overall item.

    In order to ease the transition between colors I added a behavior as shown below. However, once I add the behavior the color is frozen (does not change) when the variables change, and no error is shown.

    What is wrong?

    Rectangle {
        id: rectItemBackground
        color: backgroundColor()
        implicitWidth:  parent.width  -rectRightItemBackground.width/2
        implicitHeight: itemHeightByDepth(_depth)
    
        Behavior on color {
                NumberAnimation { duration: 1000 }
            }
    
    }
    
    function backgroundColor() {
        if (_selected) return gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected);
        if (_onSelectedPath) return gui.colorRGBString(GUIConstants.EColorElement_BackgroundPartialSelected);
        return gui.colorRGBString(GUIConstants.EColorElement_Background);
    }
    
    ocgltdO 1 Reply Last reply
    0
    • ocgltdO ocgltd

      I have a simple rectangle (below) whose color depends on a function. It works great, changing between 3 colors depending on properties of the overall item.

      In order to ease the transition between colors I added a behavior as shown below. However, once I add the behavior the color is frozen (does not change) when the variables change, and no error is shown.

      What is wrong?

      Rectangle {
          id: rectItemBackground
          color: backgroundColor()
          implicitWidth:  parent.width  -rectRightItemBackground.width/2
          implicitHeight: itemHeightByDepth(_depth)
      
          Behavior on color {
                  NumberAnimation { duration: 1000 }
              }
      
      }
      
      function backgroundColor() {
          if (_selected) return gui.colorRGBString(GUIConstants.EColorElement_BackgroundSelected);
          if (_onSelectedPath) return gui.colorRGBString(GUIConstants.EColorElement_BackgroundPartialSelected);
          return gui.colorRGBString(GUIConstants.EColorElement_Background);
      }
      
      ocgltdO Offline
      ocgltdO Offline
      ocgltd
      wrote on last edited by
      #2

      Seems to be an error in the docs (in an example). Once I used ColorAnimation instead of NumberAnimation it worked.

      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