在本页

OpacityMask QML Type

用另一个项目屏蔽源项目。更多

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

Item

属性

详细说明

注意: MultiEffect 组件提供了具有一定性能优势的遮罩效果。对于新代码,应考虑将其作为使用 Qt XMLGraphical Effects 的替代方案。

源代码遮罩源应用的效果

示例

下面的示例展示了如何应用效果。

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

该属性控制源掩码的 alpha 值的行为方式。

如果此属性为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.