本页内容

BoundaryRule QML Type

定义了数值属性可设置的值范围限制。更多...

Import Statement: import Qt.labs.animation

属性

信号

方法

详细说明

边界规则(BoundaryRule)定义了特定属性允许取值的范围。当试图设置超出该范围的值时,它会通过缓动曲线施加“阻力”。

例如,以下 BoundaryRule 可防止 `DragHandler ` 将矩形拖动得太远:

import QtQuick
import Qt.labs.animation

Rectangle {
    id: root
    width: 170; height: 120
    color: "green"

    DragHandler {
        id: dragHandler
        yAxis.minimum: -1000
        xAxis.minimum: -1000
        onActiveChanged: if (!active) xbr.returnToBounds();
    }

    BoundaryRule on x {
        id: xbr
        minimum: -50
        maximum: 100
        minimumOvershoot: 40
        maximumOvershoot: 40
    }
}

请注意,一个属性最多只能分配一个 BoundaryRule。

另请参阅 《Qt Quick 中的动画与过渡》、行为示例, Qt Qml以及《Qt Quick 示例——指针处理程序》。

属性文档

currentOvershoot : real

该属性存储被拦截属性最近设置的值超过maximum 或小于minimum 的数值。

如果属性值大于maximum ,则该属性值为正;如果属性值小于minimum ,则该属性值为负;如果属性值介于这两个边界之间,则该属性值为 0。

easing : enumeration

该属性存储在超调模式下要应用的缓动曲线(即当违反minimum 或maximum 约束条件时,且数值仍处于相应的超调范围内)。

默认缓动曲线为QEasingCurve::OutQuad 。

enabled : bool

该属性用于确定当被跟踪的属性值发生变化时,规则是否会被执行。

默认情况下,BoundaryRule 处于启用状态。

maximum : real

该属性存储该属性允许具有的最大无约束值。如果该属性被设置为更大的值,则将受easing 和maximumOvershoot 的约束。

默认值为1 。

maximumOvershoot : real

该属性存储该属性允许超出maximum 的数值。当该值大于maximum 且小于maximum + maximumOvershoot 时,其受easing 曲线的约束。当该值试图超过maximum + maximumOvershoot 时,将触发硬性停止。

默认值为 0。

minimum : real

该属性存储该属性允许具有的最小无约束值。如果将该属性设置为更小的值,则该值将受easing 和minimumOvershoot 的约束。

默认值为0 。

minimumOvershoot : real

该属性控制该属性值可以低于minimum 的最大幅度。当该值小于minimum 且大于minimum - minimumOvershoot 时,其受easing 曲线的约束。当该值试图降至minimum - minimumOvershoots 以下时,将触发硬性限制。

默认值为0 。

overshootFilter : enumeration

此属性指定将应用于被拦截的属性值的聚合函数。

如果将其设置为BoundaryRule.None (默认值),则拦截的属性将保持一个值,其超限范围限制在currentOvershoot 。如果将其设置为BoundaryRule.Peak ,则拦截的属性将保持一个值,其超限范围限制在peakOvershoot 。

overshootScale : real

该属性用于指定在超调条件下,easing 的缩放量。 例如,如果某个控件被限制在某限值之外的移动距离不得超过 100 像素,而用户(通过某个输入处理程序)试图将其拖动 100 像素超出该限值,如果 overshootScale 设置为 1,用户将能够成功操作: 缓动曲线唯一的作用是改变项目从超调 0 到超调 100 之间的移动速率。但如果将其设置为 0.5,BoundaryRule 会提供阻力,使得当用户试图移动 100 像素时,该项目只会移动 50 像素; 而缓动曲线则调节移动速率,使其在开始时可能与用户的尝试移动保持同步,随后根据缓动曲线的形状逐渐减速。

默认值为 0.5。

peakOvershoot : real

该属性保存currentOvershoot 中迄今为止观察到的最大正值或最小负值,直到调用returnToBounds()为止。

当已知被拦截的属性值会波动,且您希望检测并响应最大超调量(而非波动本身)时,此功能会非常有用。

另请参阅 overshootFilter 。

returnDuration : int

该属性表示returnToBounds()函数将花费多少时间(以毫秒为单位)将目标属性调整到最接近的边界值。如果将其设置为0,returnToBounds()函数将立即设置该属性,而不会创建动画任务。

默认值为 100 毫秒。

Signal 文档

returnedToBounds()

当currentOvershoot 在maximum 或minimum 约束被违反后,再次返回0 时,会发出此信号。如果返回过程带有动画效果,则该信号会在动画完成时发出。

注意: 相应的处理程序 是onReturnedToBounds 。

另请参阅 returnDuration 和returnToBounds()。

方法文档

bool returnToBounds()

将拦截的属性值调整为介于minimum 和maximum 之间的数值,使得currentOvershoot 和peakOvershoot 均等于零。若returnDuration 大于零,则会进行动画效果。

如果该值需要调整,则返回 true;如果该值已处于有效范围内,则返回 false。

另请参阅 returnedToBounds 。

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