Displace QML Type
根据给定的位移图移动源项的像素。更多...
| Import Statement: | import Qt5Compat.GraphicalEffects |
| Since: | QtGraphicalEffects 1.0 |
| Inherits: |
属性
- cached : bool
- displacement : real
- displacementSource : variant
- source : variant
详细说明
| 来源 | 位移源 | 已应用的效果 |
|---|---|---|
|
|
|
示例
以下示例演示了如何应用该效果。
import QtQuick
import Qt5Compat.GraphicalEffects
Item {
width: 300
height: 300
Image {
id: bug
source: "images/bug.jpg"
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
visible: false
}
Rectangle {
id: displacement
color: Qt.rgba(0.5, 0.5, 1.0, 1.0)
anchors.fill: parent
visible: false
Image {
anchors.centerIn: parent
source: "images/glass_normal.png"
sourceSize: Qt.size(parent.width/2, parent.height/2)
smooth: true
}
}
Displace {
anchors.fill: bug
source: bug
displacementSource: displacement
displacement: 0.1
}
}属性文档
cached : bool
此属性允许将效果输出的像素缓存起来,以提高渲染性能。
每次更改源或效果属性时,缓存中的像素都必须进行更新。由于需要额外的内存缓冲区来存储效果输出,因此内存消耗会增加。
当源或效果属性进行动画处理时,建议禁用缓存。
默认情况下,该属性设置为“false ”。
displacement : real
此属性定义了位移的缩放比例。缩放比例越大,像素的位移就越大。将该值设置为 0.0 时,不会产生位移。
该值的取值范围为 -1.0(反向最大偏移,参考displacementSource )到 1.0(最大偏移,参考displacementSource )。默认情况下,该属性设置为0.0 (无偏移)。
| 不同位移值的输出示例 | ||
|---|---|---|
|
|
|
| 位移:-0.2 | displacement: 0.0 | displacement: 0.2 |
displacementSource : variant
该属性定义了将用作位移贴图的对象。displacementSource 对象会被渲染到中间像素缓冲区中。结果中的红色和绿色分量值决定了源对象中像素的位移量。
位移贴图的格式与切线空间法线贴图类似,可通过大多数 3D 建模工具创建。 许多图像处理工具都支持生成法线贴图。此外,该特效的位移贴图也可以是一个颜色设置得当的 QML 元素。与任何 QML 元素一样,它可以进行动画处理。建议位移贴图的尺寸与source 的尺寸一致。
位移数据以 RGBA 格式进行解析。对于每个像素:红色通道存储 x 轴位移,绿色通道存储 y 轴位移。蓝色和 alpha 通道在此效果中被忽略。
假设红色通道值 1.0 表示纯红色(0.0 表示完全没有红色),则该效果将像素分量值 0.5 视为不产生任何偏移。大于 0.5 的值会将像素向左偏移,小于 0.5 的值则向右偏移。 同理,绿色通道值大于 0.5 时,像素向上偏移;小于 0.5 时,像素向下偏移。实际的像素偏移量取决于displacement 属性。
source : variant
此属性定义了将根据displacementSource 中的数据进行位移的像素的源项。
注意: 不支持让效果包含其自身,例如将源设置为该效果的父级。
© 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.





