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:
- Rectangle {ID: rect1 ;...}
- 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:
- Rectangle {ID: rect1 ;...}
- 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:
- Item {
- ID: group1
- Rectangle {ID: rect1 ;...}
- }
- Item {
- ID: group2
- Rectangle {ID: rect2; anchors. Left: rect1.right;...} // invalid anchor!
- }
Copy code
|
Http://www.thisisqt.com/forum/viewthread.php? Tid = 123