Anchor-based layout in qml)

Source: Internet
Author: User
In addition to traditional grids and row and column la s, Qml It also provides an anchor-based layout. Based on the anchor layout, we can imagine that each element has seven anchor lines: Left, horizontalcenter, right ), top, verticalcenter, and baseline
Baseline and bottom ).

As shown in:



Here, the baseline is the same as the top line for text elements without text.

In the qml anchor locating system, we can use the anchor to locate the positional relationship of elements. For example:

  1. Rectangle {ID: rect1 ;...}
  2. Rectangle {ID: rect2; anchors. Left: rect1.right ;...}

CopyCode

Here, the left anchor of rect2 is equal to the right anchor of rect1, so the result will be as follows:



In the qml anchor positioning system, we can also specify the margin and offset of the element.


In the following example, we specify the left margin:

  1. Rectangle {ID: rect1 ;...}
  2. Rectangle {ID: rect2; anchors. Left: rect1.right; anchors. leftmargin: 5 ;...}

Copy code

There will be a 5-pixel interval between them, and the display effect will be as follows:


For efficiency, you can only use an anchor to locate an element at the same level or its parent element. Using an anchor as follows will be considered illegal:

  1. Item {
  2. ID: group1
  3. Rectangle {ID: rect1 ;...}
  4. }
  5. Item {
  6. ID: group2
  7. Rectangle {ID: rect2; anchors. Left: rect1.right;...} // invalid anchor!
  8. }

Copy code

Http://www.thisisqt.com/forum/viewthread.php? Tid = 123

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.