Positioner QML Type

提供附加属性,其中包含项目在定位器中存在位置的详细信息。更多

Import Statement: import QtQuick

附加属性

详细说明

Positioner 类型的对象附加到列、行、流或网格中的顶层子项目。它提供的属性可让子项确定自己在父 "列"、"行"、"流 "或 "网格 "布局中的位置。

例如,下面是通过Repeater 创建的带有 16 个子矩形的Grid 。每个Rectangle 都会使用Positioner.index 显示其在网格中的索引,第一个项目会根据Positioner.isFirstItem 显示不同的颜色:

Grid {
    Repeater {
        model: 16

        Rectangle {
            id: rect
            width: 30; height: 30
            border.width: 1
            color: Positioner.isFirstItem ? "yellow" : "lightsteelblue"

            Text { text: rect.Positioner.index }
        }
    }
}

附加属性文档

Positioner.isFirstItem : bool [read-only]

Positioner.isLastItem : bool [read-only]

通过这些属性,项目可分别确定自己是定位器中的第一个还是最后一个项目。


Positioner.index : int [read-only]

该属性允许项目确定其在定位器中的索引。


© 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.