What is the default anchoring position of an item to a view/screen?



  • Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle{
            id: rec
            color: "red"
            width: 250
            height: 150
            visible: true
        }
    }
    

    In the above code, what would be the default anchor position w.r.t top, right, left and bottom ?
    Actually in the above example, i am unable to understand whether x,y values are considered for positioning or is it anchors that are taking care of positioning: which has the most priority over qml element positioning?

    What exactly would be the difference between anchors and x,y"


  • Moderators

    You don't have any anchors defined in the code you pasted, so no anchoring is done at all. Position is determined solely by x,y. Both x and y have value of 0 (zero) by default.

    What exactly would be the difference between anchors and x,y"

    x and y determine position away from parent's top-left corner. If you move the parent, these coordinates will not be updated.

    anchors determine where an item is "hooked into" it's parent. When the parent moves, an anchored child will move as well.



  • This post is deleted!


  • @sierdzio Thanks a lot!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.