Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Trouble with anchors



  • Let's say I have a given space: 360x860 or what-have-you and I want to use anchors to align a Rectangle s/t it's on the center of the horizontal access like so:

    anchors.horizontalCenter: parent.horizontalCenter
    

    great now my rectangle will be centered s/t the center of it's horizontal axis is @ 180. Now lets say I split the vertical axis up into 4 quadrants starting from the top of the page moving down I will have: q1, q2, q3 and q4 all of which will be 215 px in height. Can I center my original Rectangle on the vertical axis q4 line using anchors somehow? Obviously I could just calculate it:

    q1 (0-215), q2(215-430), q3(430-645), q4(645-860)

    therefore I could say:

    Rectangle
    {
      anchors.horizontalCenter: parent.horizontalCenter
      y: 645
    }
    

    The problem here is I am not using anchors and I was told to always use them if I could. Something like this:

    anchors.verticalCenter: parent.verticleCenter/2
    

    Obviously, this wont work because this could refer to two different locations q2 line or q4 but hopefully it gets my point across about what I am trying to do here.




Log in to reply