本页内容

Row QML Type

将子元素排列成一行。更多...

Import Statement: import QtQuick
Inherits:

Item

属性

信号

方法

详细说明

Row 是一种将子项沿单行排列的布局类型。它提供了一种便捷的方式,可在无需使用锚点的情况下水平排列一系列项。

下面是一个包含三个不同大小矩形的 Row:

import QtQuick

Row {
    spacing: 2
    Rectangle { color: "red"; width: 50; height: 50 }
    Rectangle { color: "green"; width: 20; height: 50 }
    Rectangle { color: "blue"; width: 50; height: 20 }
}

Row 会自动将这些项目以水平排列的方式布局,如下所示:

三个彩色矩形水平排列成一排

如果 Row 中的某个项目不是visible ,或者其宽度或高度为 0,则该项目不会被布局,也不会显示在 Row 中。此外,由于 Row 会自动将子项水平排列,因此 Row 中的子项不应设置其x 位置,也不应使用left 、right 、anchors.horizontalCenter 、fill 或centerIn 锚点进行水平定位。 如果您需要执行这些操作,请考虑在不使用行(Row)的情况下定位项目。

请注意,行中的项目可以使用Positioner 附加属性来获取其在行内位置的更多信息。

有关使用 Row 及其他相关定位器类型的更多信息,请参阅“项目定位器”。

另请参阅 Column 、Grid 、Flow 、Positioner 、RowLayout 以及Qt Quick 示例 - 定位器。

属性文档

add : Transition

该属性用于存储添加到该定位器中的项目应执行的过渡效果。对于定位器而言,这适用于:

  • 在定位器创建后,作为其子项被创建或重新父级化的项目
  • 将Item::visible 属性从false更改为true,从而变为可见状态的子项

该过渡效果可使用 `ViewTransition ` 属性来获取有关正在添加的项的更多详细信息。有关使用这些过渡效果的更多详细信息和示例,请参阅ViewTransition 文档。

注意:此 过渡效果不适用于在定位器创建时已属于该定位器的项目。在此情况下,将应用populate 过渡效果。

另请参阅 populate 、ViewTransition 以及Qt Quick 示例 - 定位器。

bottomPadding : real

leftPadding : real

padding : real

rightPadding : real

topPadding : real

这些属性用于控制内容周围的填充。

effectiveLayoutDirection : enumeration [read-only]

该属性用于指定行布局的有效方向。

当使用附加属性LayoutMirroring::enabled 进行区域布局时,行定位器的视觉布局方向将被镜像。但属性layoutDirection 将保持不变。

另请参阅 Row::layoutDirection 和LayoutMirroring 。

layoutDirection : enumeration

该属性存储行(row)的布局方向(layoutDirection)。

可能的取值:

常量描述
Qt.LeftToRight(默认)项目从左到右排列。如果显式设置了行宽,则左锚点仍位于行的左侧。
Qt.RightToLeft项目从右向左排列。如果显式设置了行宽,则右锚点仍位于行的右侧。

另请参阅 Grid::layoutDirection 和Flow::layoutDirection 。

move : Transition

此属性用于控制在定位器内发生位移的元素的过渡效果。对于定位器而言,这适用于:

  • 因定位器中其他元素的添加、移除或重新排列而导致位置发生偏移的子元素
  • 因定位器中其他元素调整大小而重新定位的子元素

该过渡可通过 `ViewTransition ` 属性获取有关正在移动的项的更多详细信息。但请注意,对于此移动过渡,`ViewTransition.targetIndexes` 和 `ViewTransition.targetItems` 列表仅在该过渡由定位器中其他项的添加触发时才会被设置;在其他情况下,这些列表将为空。 有关使用这些过渡的更多详细信息和示例,请参阅ViewTransition 文档。

另请参阅 add 、populate 、ViewTransition 以及Qt Quick 示例 - 定位器。

populate : Transition

该属性存储了在该定位器创建时,属于该定位器的项目将执行的过渡效果。该过渡效果在定位器首次创建时执行。

该过渡可使用ViewTransition 属性来获取有关正在添加的项的更多详细信息。有关使用这些过渡的更多详细信息和示例,请参阅ViewTransition 文档。

另请参阅 add 、ViewTransition 以及Qt Quick 示例 - 定位器。

spacing : real

间距是指相邻项目之间留出的空白区域,单位为像素。默认间距为 0。

另请参阅 Grid::spacing 。

Signal 文档

positioningComplete()

当定位完成时,会发出此信号。

注意: 相应的处理程序 为onPositioningComplete 。

方法文档

void forceLayout()

Row 通常每帧仅对子元素定位一次。这意味着在脚本块内部,底层子元素可能已经发生变化,但 Row 尚未相应地更新。

此方法会强制 Row 立即响应其子元素中任何未处理的更改。

注意:通常情况下,方法应在组件加载完成后才调用。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.