InnerShadow QML Type
在源文件内部生成彩色模糊阴影。更多
Import Statement: | import Qt5Compat.GraphicalEffects |
Since: | QtGraphicalEffects 1.0 |
Inherits: |
属性
- cached : bool
- color : color
- fast : bool
- horizontalOffset : real
- radius : real
- samples : int
- source : variant
- spread : real
- verticalOffset : real
详细说明
默认情况下,该特效会生成高质量的阴影图像,因此阴影的渲染速度可能不会最高。尤其是当阴影边缘被大量柔化时,渲染速度会降低。对于需要更快的渲染速度但不需要最高视觉质量的使用情况,可以将属性fast 设为 true。
来源 | 应用的效果 |
---|---|
注: 此效果在使用 OpenGL 运行时可用。
示例
下面的示例展示了如何应用该效果。
import QtQuick import Qt5Compat.GraphicalEffects Item { width: 300 height: 300 Rectangle { anchors.fill: parent } Image { id: butterfly source: "images/butterfly.png" sourceSize: Qt.size(parent.width, parent.height) smooth: true visible: false } InnerShadow { anchors.fill: butterfly radius: 8.0 samples: 16 horizontalOffset: -3 verticalOffset: 3 color: "#b0000000" source: butterfly } }
属性文档
cached : bool |
此属性允许缓存效果输出像素,以提高渲染性能。每次更改源或特效属性时,都必须更新缓存中的像素。由于需要额外的内存缓冲区来存储效果输出,因此会增加内存消耗。
建议在动画源或特效属性时禁用缓存。
默认情况下,该属性设置为false
。
color : color |
该属性定义用于阴影的 RGBA 颜色值。
默认情况下,该属性设置为"black"
。
不同颜色值的输出示例 | ||
---|---|---|
颜色#000000 | color:#ffffff | 颜色#ff0000 |
radius:16 | radius:16 | radius:16 |
samples: 24 | samples: 24 | samples: 24 |
horizontalOffset:0 | horizontalOffset:0 | horizontalOffset:0 |
verticalOffset:0 | verticalOffset:0 | verticalOffset:0 |
spread:0.2 | spread:0.2 | spread:0.2 |
fast : bool |
此属性选择用于产生柔和效果的模糊算法。将其设置为 true 可以使用快速算法,设置为 false 则会产生更高质量的效果。
默认情况下,该属性设置为false
。
不同快速值的输出示例 | ||
---|---|---|
fast: false | fast: true | |
radius:16 | radius:16 | |
samples: 24 | samples: 24 | |
color:#000000 | color:#000000 | |
horizontalOffset:0 | horizontalOffset:0 | |
verticalOffset:0 | verticalOffset:0 | |
spread:0.2 | spread:0.2 |
horizontalOffset : real |
HorizontalOffset 和verticalOffset 属性定义了渲染阴影相对于InnerShadow 项位置的偏移量。通常情况下,InnerShadow 项会被锚定,以填充源元素。在这种情况下,如果 HorizontalOffset 和verticalOffset 属性设置为 0,阴影就会完全呈现在源项内部。通过更改偏移属性,阴影可以相对于源项定位。
偏移属性的取值范围为 -inf 至 inf。默认情况下,属性设置为0
。
不同水平偏移值的输出示例 | ||
---|---|---|
水平偏移:-20 | horizontalOffset: 0 | 水平偏移:20 |
radius:16 | radius:16 | radius:16 |
samples: 24 | samples: 24 | samples: 24 |
color:#000000 | color:#000000 | color:#000000 |
verticalOffset:0 | verticalOffset:0 | verticalOffset:0 |
spread:0 | spread:0 | spread:0 |
radius : real |
半径定义阴影的柔和度。半径越大,阴影边缘越模糊。
根据半径值,samples 的值应该设置得足够大,以确保视觉质量。
数值范围从 0.0(无模糊)到 inf。默认情况下,该属性设置为0.0
(无模糊)。
不同半径值的输出示例 | ||
---|---|---|
半径:0 | 半径:6 | 半径:12 |
samples: 24 | samples: 24 | samples: 24 |
color:#000000 | color:#000000 | color:#000000 |
horizontalOffset:0 | horizontalOffset:0 | horizontalOffset:0 |
verticalOffset:0 | verticalOffset:0 | verticalOffset:0 |
spread:0 | spread:0 | spread:0 |
samples : int |
此属性定义边缘柔化模糊计算时每个像素取样的数量。数值越大,质量越好,但渲染速度越慢。
理想情况下,该值应是所需最高半径值的两倍,例如,如果半径在 0.0 和 4.0 之间,样本数应设置为 8。
数值范围为 0 至 32。默认情况下,该属性设置为0
。
该属性不用于动画。更改此属性可能会导致重新编译底层 OpenGL 着色器。
当fast 属性设置为 true 时,该属性将不起作用。
source : variant |
此属性定义了将用作生成阴影的源项。
注意: 不支持让效果包含自身,例如将源设置为效果的父项。
spread : real |
该属性定义了阴影颜色在源边缘附近的强化程度。
数值范围为 0.0 至 1.0。默认情况下,该属性设置为0.5
。
不同扩散值的输出示例 | ||
---|---|---|
展开:0.0 | 扩散:0.3 | 传播:0.5 |
radius:16 | radius:16 | radius:16 |
samples: 24 | samples: 24 | samples: 24 |
color:#000000 | color:#000000 | color:#000000 |
horizontalOffset:0 | horizontalOffset:0 | horizontalOffset:0 |
verticalOffset:0 | verticalOffset:0 | verticalOffset:0 |
verticalOffset : real |
HorizontalOffset 和 verticalOffset 属性定义了渲染阴影相对于InnerShadow 项目位置的偏移量。通常情况下,InnerShadow 项会被锚定,以便填满源元素。在这种情况下,如果 HorizontalOffset 和 verticalOffset 属性设置为 0,阴影就会完全呈现在源项内部。通过更改偏移属性,阴影可以相对于源项定位。
偏移属性的取值范围为 -inf 至 inf。默认情况下,属性设置为0
。
不同horizontalOffset 值的输出示例 | ||
---|---|---|
horizontalOffset: -20 | horizontalOffset: 0 | horizontalOffset: 20 |
radius:16 | radius:16 | radius:16 |
samples: 24 | samples: 24 | samples: 24 |
color:#000000 | color:#000000 | color:#000000 |
verticalOffset: 0 | verticalOffset: 0 | verticalOffset: 0 |
spread:0 | spread:0 | spread:0 |
© 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.