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" 。
| 使用不同颜色值的输出示例 | ||
|---|---|---|
|
|
|
| color: #000000 | color: #ffffff | color: #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”值下的输出示例 | ||
|---|---|---|
|
| |
| 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 。
| 不同 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 |
radius : real
半径决定了阴影的柔和程度。半径越大,阴影的边缘看起来就越模糊。
根据半径的数值,应将“samples ”的数值设置得足够大,以确保视觉效果的质量。
该值范围从 0.0(无模糊)到无穷大。默认情况下,该属性设置为0.0 (无模糊)。
| 不同半径值的输出示例 | ||
|---|---|---|
|
|
|
| 半径:0 | radius: 6 | radius: 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 。
| 不同扩散值下的输出示例 | ||
|---|---|---|
|
|
|
| spread:0.0 | spread: 0.3 | spread: 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 |
| 垂直偏移:0 | 垂直偏移:0 | 垂直偏移量:0 |
| spread: 0 | spread: 0 | spread: 0 |
© 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.















