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. How to find distance from one item to other

How to find distance from one item to other

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

    Hi, I have a green rectangle, i want to find the distance from green rectangle bottom to red rectangle bottom.

    Rectangle
    {
        id: rec
        height: 200
        width: 200
        color: "red"
    
        Rectangle
        {
            width: 20
            height: 20
            color: "green"
            x:20
            y:40
        }
    }
    
    

    0_1551089057014_distance.png

    M 1 Reply Last reply
    0
    • Bhushan_SureB Bhushan_Sure

      Hi, I have a green rectangle, i want to find the distance from green rectangle bottom to red rectangle bottom.

      Rectangle
      {
          id: rec
          height: 200
          width: 200
          color: "red"
      
          Rectangle
          {
              width: 20
              height: 20
              color: "green"
              x:20
              y:40
          }
      }
      
      

      0_1551089057014_distance.png

      M Offline
      M Offline
      Mammamia
      wrote on last edited by
      #2

      @Bhushan_Sure

      Use the Y position and height to calculate the distance.
      Updated your code snippet with calculation.

      Rectangle
          {
              id: rectRed
              height: 200
              width: 200
              color: "red"
      
              Text {
                  id: distance
                  anchors.centerIn: parent
                  text: "distance = " + ((rectRed.y + rectRed.height) - (rectGreen.y + rectGreen.height))
              }
      
              Rectangle
              {
                  id: rectGreen
                  width: 20
                  height: 20
                  color: "green"
                  x:20
                  y:40
              }
          }
      

      I hope this si the same you are seeking for.

      Bhushan_SureB 1 Reply Last reply
      3
      • M Mammamia

        @Bhushan_Sure

        Use the Y position and height to calculate the distance.
        Updated your code snippet with calculation.

        Rectangle
            {
                id: rectRed
                height: 200
                width: 200
                color: "red"
        
                Text {
                    id: distance
                    anchors.centerIn: parent
                    text: "distance = " + ((rectRed.y + rectRed.height) - (rectGreen.y + rectGreen.height))
                }
        
                Rectangle
                {
                    id: rectGreen
                    width: 20
                    height: 20
                    color: "green"
                    x:20
                    y:40
                }
            }
        

        I hope this si the same you are seeking for.

        Bhushan_SureB Offline
        Bhushan_SureB Offline
        Bhushan_Sure
        wrote on last edited by
        #3

        @Mammamia Thank you very much :)

        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