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. Changing rectangle position that is depending to another rectangle position
QtWS25 Last Chance

Changing rectangle position that is depending to another rectangle position

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

    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
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      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
      0

      • Login

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