Column QML Type
在列中定位其子节点。更多
Import Statement: | import QtQuick |
Inherits: |
属性
- add : Transition
- bottomPadding : real
- leftPadding : real
- move : Transition
- padding : real
- populate : Transition
- rightPadding : real
- spacing : real
- topPadding : real
信号
方法
详细说明
列(Column)是一种可以沿单列定位其子项的类型。它是一种无需使用锚点即可垂直定位一系列项目的便捷方法。
下面是一个包含三个不同大小矩形的列:
Column { spacing: 2 Rectangle { color: "red"; width: 50; height: 50 } Rectangle { color: "green"; width: 20; height: 50 } Rectangle { color: "blue"; width: 50; height: 20 } }
该列会自动将这些项目垂直定位,就像下面这样:
如果列中的项目不是visible ,或者其宽度或高度为 0,则该项目将不会布局,在列中也不可见。此外,由于 "列 "会自动垂直定位其子项,因此 "列 "中的子项不应设置其y 位置,也不应使用top 、bottom 、anchors.verticalCenter 、fill 或centerIn 锚点垂直锚定自己。如果需要执行这些操作,请考虑不使用列来定位项目。
请注意,列中的项目可以使用Positioner attached 属性来访问有关其在列中位置的更多信息。
有关使用列和其他相关定位器类型的更多信息,请参阅项目定位器。
使用过渡效果
当项目添加到列中或在列中移动时,列会使用特定的过渡效果将项目动画化。
例如,下面的列将move 属性设置为特定的Transition :
Column { spacing: 2 Rectangle { color: "red"; width: 50; height: 50 } Rectangle { id: greenRect; color: "green"; width: 20; height: 50 } Rectangle { color: "blue"; width: 50; height: 20 } move: Transition { NumberAnimation { properties: "x,y"; duration: 1000 } } focus: true Keys.onSpacePressed: greenRect.visible = !greenRect.visible }
按空格键时,绿色Rectangle 的visible 值会发生切换。随着它的出现和消失,蓝色Rectangle 会在列内移动,而move 过渡会自动应用到蓝色Rectangle 上:
另请参阅 Row,Grid,Flow,Positioner,ColumnLayout 和Qt Quick 示例 - 定位器。
属性文档
这些属性包含内容周围的填充。
add : Transition |
此属性为添加到此定位器的项目所要运行的转换。对于定位器,这适用于
- 在定位器创建后作为定位器的子项创建或重新赋予的项目
- 将Item::visible 属性从 false 变为 true 并因此现在可见的子项目
过渡可以使用ViewTransition 属性访问有关正在添加的项目的更多详细信息。有关使用这些转换的更多详情和示例,请参阅ViewTransition 文档。
注意: 此转换不会应用于创建时已是定位器一部分的项目。在这种情况下,将应用populate 过渡。
另请参阅 populate,ViewTransition, 和Qt Quick 示例 - 定位器。
move : Transition |
此属性用于保存在定位器中移动的项目的转换。对于定位器,该属性适用于
- 由于在定位器中添加、移除或重新排列其他项目而发生位移的子项目
- 由于定位器中其他项目的大小调整而重新定位的子项目
过渡可以使用ViewTransition 属性来访问有关被移动项目的更多详细信息。但请注意,对于此移动过渡,ViewTransition.targetIndexes 和ViewTransition.targetItems 列表只有在定位器中添加其他项目触发此过渡时才会被设置;在其他情况下,这些列表将为空。有关使用这些转换的更多详情和示例,请参阅ViewTransition 文档。
populate : Transition |
此属性用于保存在创建定位器时作为其一部分的项目的过渡。过渡在定位器首次创建时运行。
过渡可以使用ViewTransition 属性来访问有关正在添加的项目的更多详细信息。有关使用这些转换的更多详情和示例,请参阅ViewTransition 文档。
另请参阅 add 、ViewTransition 和Qt Quick 示例 - 定位器。
spacing : real |
间距是指相邻项目之间留空的像素数。默认间距为 0。
另请参阅 Grid::spacing 。
信号文档
positioningComplete() |
定位完成后会发出此信号。
注: 相应的处理程序是onPositioningComplete
。
方法文档
forceLayout() |
列通常每帧定位其子节点一次。这意味着在脚本块内,底层子代有可能已经更改,但列尚未相应更新。
此方法可强制列立即响应其子列中任何未完成的更改。
注意:一般情况下,方法只能在组件完成后调用。
© 2025 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.