October 26, 2010

2beers 2beers
Lab Rat
149 posts

changing rectangle position that is depending to another rectangle position

 

Hi everyone. in the following code the blue rectangle position is set to 120 px + red rectangle position. if I change the red rectangle position , it also changes the blue rectangle position. what do I need to do to not maintain the blue rectangle position(not depending on red rectangle position) ?

  1. import Qt 4.7
  2.  
  3. Rectangle {
  4.     width: 640
  5.     height: 480
  6.  
  7.  
  8.     Rectangle{
  9.         id:redRectangle
  10.         x:10
  11.         y:10
  12.         width:100
  13.         height:100
  14.         color: "red"
  15.  
  16.         MouseArea{
  17.             anchors.fill: parent;
  18.             onClicked:parent.x+=100
  19.         }
  20.     }
  21.  
  22.     Rectangle{
  23.         id:blueRectangle
  24.         x:redRectangle.x+120
  25.         y:10
  26.         width:100
  27.         height:100
  28.         color: "blue"
  29.  
  30.     }
  31.  
  32.  
  33. }

1 reply

October 27, 2010

mbrasser mbrasser
Lab Rat
452 posts

Are you looking for blueRectangle to initially be positioned at rectRectangle.x + 120, but not bound to it? (so changing redRectangle.x does not cause blueRectangle to move?) In that case you could either use an absolute value for the position of blueRectangle, or assign a value to blueRectangle.x at component completion:

  1. // this assigns a value, and does *not* establish a binding
  2. Component.onCompleted: blueRectangle.x = redRectangle.x+120

 
  ‹‹ Loader Element      Video and Audio elements ››

You must log in to post a reply. Not a member yet? Register here!