本页内容

OpacityMask QML Type

用另一个项目遮盖源项目。更多...

Import Statement: import Qt5Compat.GraphicalEffects
Since: QtGraphicalEffects 1.0
Inherits:

Item

属性

详细说明

注意: MultiEffect 组件提供了一种 具有一定性能优势的蒙版效果。对于新代码,应将其视为 QtGraphical Effects 的替代方案。

源代码MaskSource应用的效果

叶子上的黑甲虫

圆形渐变蒙版

装有圆形面罩的甲壳虫

示例

以下示例演示了如何应用该效果。

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
    }

    Image {
        id: mask
        source: "images/butterfly.png"
        sourceSize: Qt.size(parent.width, parent.height)
        smooth: true
        visible: false
    }

    OpacityMask {
        anchors.fill: bug
        source: bug
        maskSource: mask
    }
}

属性文档

cached : bool

此属性允许将效果输出像素缓存起来,以提升渲染性能。

每次更改源或效果属性时,缓存中的像素都必须更新。由于需要额外的内存缓冲区来存储效果输出,因此内存消耗会增加。

当源或效果属性被动画化时,建议禁用缓存。

默认情况下,该属性设置为false 。

注意: 不支持让效果包含自身,例如将maskSource 设置为效果的父级。

invert : bool

此属性控制源蒙版(sourceMask)的透明度值如何变化。

如果该属性值为false ,则最终的不透明度等于源透明度与遮罩透明度的乘积,即As * Am 。

如果此属性为true ,则最终的不透明度为源透明度乘以蒙版透明度的倒数,即As * (1 - Am) 。

默认值为false 。

maskSource : variant

该属性定义了将用作蒙版的项目。蒙版项目会被渲染到一个中间像素缓冲区中,并根据结果中的Alpha值来确定源项目像素在显示中的可见性。

原始蒙版应用效果

叶子上的黑甲虫

圆形渐变蒙版

装有圆形面罩的甲壳虫

source : variant

此属性用于定义将被遮罩的源项目。

注意: 不支持让效果包含自身,例如将“源”设置为该效果的父级。

© 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.