Qt Quick 示例 - 项目可变刷新率
一个“Qt Quick ”示例演示了如何为用户界面的特定部分设置可变刷新率。

本示例演示了如何利用Item Layers 的live属性,为“快速项目”实现可变且独立的刷新率。如果用户界面的特定部分无需每帧重新渲染,但仍需进行内部更新,此方法可显著提升性能。 渲染那些大部分时间保持静态的组件,或渲染那些无需始终流畅运行的动画,都是对资源的浪费。该属性允许用户控制项的渲染时机。
注意:使用 Item Layers 可能会带来性能开销,具体取决于分层项子树的大小。这是因为该功能会使用独立的渲染目标(纹理),这些渲染目标随后会在主渲染阶段进行混合。应用程序设计者应始终评估其影响,以确保使用分层带来的好处大于潜在的弊端。
该示例使用 `FrameAnimation ` 来控制项的渲染频率。当您仅希望每隔一帧渲染一次时,此方法非常有用。使用计时器或其他机制来切换该标志也是可行的。
FrameAnimation {
id: frameAnimation
property real fps: smoothFrameTime > 0 ? (1.0 / smoothFrameTime) : 0
running: true
}在上面的代码片段中,fps 属性仅用于视觉演示。
该项要求 layer.enabled 为 true,然后项将根据 layer.live 的状态进行渲染,如下面的代码片段所示。
Item {
id: qt_logo
width: 230
height: 230
anchors.fill: parent
anchors.topMargin: 125
layer.enabled: true
layer.live: slider.value > 0 && frameAnimation.currentFrame % slider.value == 0通过模运算符和滑块设置数值,我们可以动态调整 Qt 徽标的渲染频率。
© 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.