Q-flex:CSS 布局 → QML 布局对照表

类型CSS 布局QML 布局说明
定位position: absolute; top/leftx / y 手动定位精确像素控制
定位position: relative + 偏移anchors { } 锚定相对父级/兄弟定位
定位inset: 0(铺满父级)anchors.fill: parent铺满容器
定位Flex 容器 justify-content/align-items: centeranchors.centerIn单元素居中
定位left: 0(贴左)anchors.left: parent.left左锚线
定位right: 0(贴右)anchors.right: parent.right右锚线
定位top: 0(贴上)anchors.top: parent.top上锚线
定位bottom: 0(贴下)anchors.bottom: parent.bottom下锚线
定位left: 0; right: 0; margin: autoanchors.horizontalCenter水平居中锚线
定位top: 0; bottom: 0; margin: autoanchors.verticalCenter垂直居中锚线
弹性布局display: flex; flex-direction: rowRow水平排列
弹性布局display: flex; flex-direction: columnColumn垂直排列
弹性布局display: flex; flex-wrap: wrapFlow自动换行
弹性布局Flexbox 弹性伸缩RowLayout / ColumnLayout响应式弹性布局
网格布局display: grid; grid-template-columns: repeat(N, 1fr)Grid { columns: N }固定列数网格
网格布局Grid 弹性伸缩GridLayout弹性网格
网格布局grid-row / grid-columnLayout.rowSpan / Layout.columnSpan行列跨度
网格布局grid-row-start / grid-column-startLayout.row / Layout.column网格坐标
间距margin: 10pxanchors.margins: 10锚点边距
间距margin-left: 10pxanchors.leftMargin: 10单边边距
间距gap: 10pxspacing: 10Row / Column / Grid 间距
弹性伸缩flex: 1(水平)Layout.fillWidth: true水平填充可用空间
弹性伸缩flex: 1(垂直)Layout.fillHeight: true垂直填充可用空间
尺寸约束min-widthLayout.minimumWidth最小宽度约束
尺寸约束max-widthLayout.maximumWidth最大宽度约束
尺寸约束width: autoLayout.preferredWidth首选宽度
尺寸约束height: autoLayout.preferredHeight首选高度
对齐align-items / justify-contentLayout.alignment对齐方式(如 Qt.AlignHCenter)