本页内容

ColorOverlay QML Type

通过应用叠加颜色来更改源项的颜色。更多...

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

Item

属性

详细说明

该效果类似于将彩色玻璃覆盖在灰度图像上的效果。叠加层的颜色以ARGB格式提供。

来源已应用效果

色彩斑斓的蝴蝶图案

应用了色彩叠加效果的蝴蝶

示例

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

import QtQuick
import Qt5Compat.GraphicalEffects

Item {
    width: 300
    height: 300

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

    ColorOverlay {
        anchors.fill: bug
        source: bug
        color: "#80800000"
    }
}

属性文档

cached : bool

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

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

当源或效果属性进行动画处理时,建议禁用缓存。

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

color : color

此属性定义了用于为源内容着色的颜色值。

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

使用不同颜色值的输出示例

带红色覆层的蝴蝶

带绿色叠加层的蝴蝶

带蓝色叠加效果的蝴蝶

color: #80ff0000 color: #8000ff00 color: #800000ff

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.