ThresholdMask QML Type
使用另一个项目对源项目进行蒙版处理,并应用阈值。更多...
| Import Statement: | import Qt5Compat.GraphicalEffects |
| Since: | QtGraphicalEffects 1.0 |
| Inherits: |
属性
- cached : bool
- maskSource : variant
- source : variant
- spread : real
- threshold : real
详细说明
注意: MultiEffect 组件提供了一种 具有一定性能优势的蒙版效果。对于新代码,应将其视为替代QtGraphical Effects 的方案。
可以通过threshold 的数值来控制遮罩像素的遮罩行为。
| 源代码 | MaskSource | 应用的效果 |
|---|---|---|
|
|
|
示例
以下示例展示了如何应用该效果。
import QtQuick
import Qt5Compat.GraphicalEffects
Item {
width: 300
height: 300
Image {
id: background
anchors.fill: parent
source: "images/checker.png"
smooth: true
fillMode: Image.Tile
}
Image {
id: bug
source: "images/bug.jpg"
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
visible: false
}
Image {
id: mask
source: "images/fog.png"
sourceSize: Qt.size(parent.width, parent.height)
smooth: true
visible: false
}
ThresholdMask {
anchors.fill: bug
source: bug
maskSource: mask
threshold: 0.4
spread: 0.2
}
}属性文档
cached : bool
此属性允许将效果输出像素缓存起来,以提高渲染性能。
每次更改源或效果属性时,缓存中的像素都必须更新。由于需要额外的内存缓冲区来存储效果输出,因此内存消耗会增加。
当源或效果属性进行动画处理时,建议禁用缓存。
默认情况下,该属性设置为false 。
maskSource : variant
此属性定义了将用作蒙版的项目。蒙版项目会被渲染到一个中间像素缓冲区中,并根据结果中的透明度值来确定源项目像素在显示中的可见性。
| 原始 | 蒙版 | 应用效果 |
|---|---|---|
|
|
|
注意:不 支持让效果包含自身,例如将 maskSource 设置为该效果的父级。
source : variant
此属性定义了将被遮罩的源项目。
注意: 不支持让效果包含自身,例如将“源”设置为该效果的父级。
spread : real
此属性定义了在threshold 的Alpha值附近,蒙版边缘的平滑程度。将“扩散”设置为0.0时,将按常规方式使用蒙版,并采用指定的阈值。设置较高的“扩散”值会通过在透明蒙版像素与不透明蒙版像素之间添加插值值,从而使从透明蒙版像素向不透明蒙版像素的过渡更加平滑。
该值范围为 0.0(锐利蒙版边缘)到 1.0(平滑蒙版边缘)。默认情况下,该属性设置为0.0 。
threshold : real
此属性定义了蒙版像素的阈值。Alpha 值低于此属性的蒙版像素将用于完全遮盖源项中的相应像素。Alpha 值高于此属性的蒙版像素将用于将源项以透明混合的方式显示在屏幕上。
该值的取值范围为 0.0(Alpha 值为 0)至 1.0(Alpha 值为 255)。默认情况下,该属性设置为0.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.








