Qt Quick QML 中的 Row 是一种布局容器,用于在水平方向上排列子项。以下是一些常见的属性:
- spacing:指定子项之间的间距,默认为0。
- Layout.alignment:设置行内子项的对齐方式,默认为 Qt.AlignLeft。
- Layout.fillWidth:确定是否将空余宽度分配给行内的子项,默认为false。
- Layout.leftMargin、Layout.rightMargin、Layout.topMargin、Layout.bottomMargin:分别设置左边距、右边距、上边距和下边距。
除了这些通用属性外,Row 还可以使用 Item 的属性,如 width、height 等来控制自身的尺寸。
示例代码:
import QtQuick 2.0
import QtQuick.Layouts 1.12
Row {
spacing: 10
Layout.alignment: Qt.AlignHCenter
Layout.fillWidth: true
Rectangle {
width: 50
height: 50
color: "red"
}
Rectangle {
width: 50
height: 50
color: "green"
}
Rectangle {
width: 50
height: 50
color: "blue"
}
}
以上代码创建了一个包含三个矩形的 Row 布局容器。它们之间有10像素的间距,并且会在水平方向上居中对齐。Row 容器会自动调整子项的宽度以填充可用空间。
内容由零声教学AI助手提供,问题来源于学员提问