Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Changing rectangle position that is depending to another rectangle position

    QML and Qt Quick
    2
    2
    2199
    Loading More Posts
    • 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.
    • 2
      2beers last edited by

      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) ?

      @import Qt 4.7

      Rectangle {
      width: 640
      height: 480

      Rectangle{
          id:redRectangle
          x:10
          y:10
          width:100
          height:100
          color: "red"
      
          MouseArea{
              anchors.fill: parent;
              onClicked:parent.x+=100
          }
      }
      
      Rectangle{
          id:blueRectangle
          x:redRectangle.x+120
          y:10
          width:100
          height:100
          color: "blue"
      
      }
      

      }
      @

      1 Reply Last reply Reply Quote 0
      • M
        mbrasser last edited by

        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:

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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post