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. Trouble with anchors

Trouble with anchors

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

    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.

    ODБOïO 1 Reply Last reply
    0
    • C Circuits

      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.

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @Circuits hi
      can margins and offsets help ? https://doc.qt.io/qt-5/qtquick-positioning-anchors.html#anchor-margins-and-offsets

      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