QML There are two main layout, Anchor point layout, grid layout.
Anchor layout Use the anchors Attachment property to position the edges of one element to the edge of another, thus determining the position and size of the element. Here is an example
1 Import QtQuick 2.32 Import Qtquick.window 2.03 4 Window{5 ID:Anchorlayoutwindow;6 width:480;7 Height: the;8 title:"Anchorlayout";9 Ten rectangle{ One ID:Rect1; A width:Parent.width; - Height: -; - Color:"Blue"; the Anchors.top:Parent.top; - text{Text:"Top";Anchors.horizontalcenter:Parent.horizontalcenter;Anchors.top:Parent.top;Color:"White"; } - } - + Rectangle{ - ID:Rect2; + width:PARENT.WIDTH/4; A Color:"Red"; at Anchors.top:Rect1.bottom; - Anchors.bottom:Rect4.top - Anchors.left:parent.left; - text{Text:"left";Anchors.verticalcenter:Parent.verticalcenter;Anchors.left:Parent.left;Color:"White"; } - } - in Rectangle{ - ID:Rect3; to Color:"Green"; + width:Rect2.width; - Anchors.top:Rect1.bottom; the Anchors.bottom:Rect4.top; * Anchors.right:Parent.right; $ text{Text:"Right";Anchors.right:Parent.right;Anchors.verticalcenter:Parent.verticalcenter;Color:"White"; }Panax Notoginseng } - the Rectangle{ + ID:Rect4; A width:Parent.width; the Height: -; + Color:"Yellow"; - Anchors.bottom:Parent.bottom; $ text{Text:"Bottom";Anchors.horizontalcenter:Parent.horizontalcenter;Anchors.bottom:Parent.bottom;Color:"Blue";} $ } - - Rectangle{ the ID:Rect5; - Color:"#FF605066";Wuyi Anchors.top:Rect1.bottom; the Anchors.bottom:Rect4.top; - Anchors.left:Rect2.right; Wu Anchors.right:Rect3.left; - text{Text:"Center";Anchors.centerin:Parent;Color:"White";} About } $ - }
Effects such as
Grid layout has GridLayout, Columnlayout, Rowlayout, Column, Row, where Columnlayout, Rowlayout is only a special case of GridLayout, Columnlayout indicates that there is only one column, and Rowlayout represents one row.
GridLayout uses the columns, rows property to divide the space into several cells, using columnspacing, rowspacing to establish the spacing between the cells. The size of the inner elements of GridLayout is determined by Layout.fillwidth, Layout.fillheight, and Layout.preferredwidth, Layout.preferredheight to determine if Layout.fillWidth:true indicates that the width fills the entire cell, layout.preferredwidth specifies a suggested width. Layout.row, Layout.column determines which cell the inner element is in. Note that the inner element's width, height, x, y, and GridLayout are not bound, which can lead to binding loops.
Column, row, similar to the float in HTML or StackPanel in WPF, will directly bring the elements together, with the interval between elements using spacing control
Here is an example of the GridLayout layout
1 Import QtQuick 2.32 Import Qtquick.window 2.03 Import qtquick.layouts 1.14 5 Window{6 ID:Gridlayoutwindow;7 title:"Gridlayoutwindow";8 width:480;9 Height: the;Ten gridlayout{ One ID:GRIDLAYOUT1 A Columns:2; - rows:2; - Anchors.fill:Parent; the Anchors.margins:5; - columnspacing:0; - rowspacing:0; - + rectangle{ - ID:rect00; + Color:"Red"; A Layout.fillwidth:true; at Layout.fillheight:true; -} - - Rectangle{ - ID:rect01; - Color:"Blue"; in Layout.fillwidth:true; - Layout.fillheight:true; to} + - Rectangle{ the ID:rect10; * Color:"Green"; $ Layout.fillwidth:true;Panax Notoginseng Layout.fillheight:true; - Layout.row:1; the Layout.column:1; +} A the } + }
The effect is shown below
Splitview is used to provide a layout with a split bar, here is an example
import QtQuick 2.3import qtquick.window 2.0import qtquick.layouts 1.1import qtquick.controls 1.2Window{width:480;Height: the;title:"SplitView";splitview{Anchors.fill:Parent;Orientation:Qt.horizontal;rectangle{ID:Rect1;width: -;Color:"Red"; }Rectangle{ID:Rect2;Layout.fillwidth:true;Layout.minimumwidth: -;Color:"Blue"; }Rectangle{ID:Rect3;width: -;Color:"Green"; } }}
The following is, notice the actual situation can be dragged slitting bar
OK, with the above several layout methods, through a certain combination of believe that can deal with most of the layout needs
Qt Quick QuickStart QML layout