本页内容

Colorize QML Type

设置HSL色彩空间中的颜色。更多...

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

Item

属性

详细说明

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

该效果类似于在灰度图像上叠加一层彩色玻璃所产生的效果。Colorize 使用色相、饱和度和亮度(HSL)颜色空间。您可以为每个属性指定所需的值。通过HueSaturation 效果,您可以调整所有 HSL 值。

此外,您还可以使用“ColorOverlay ”效果,在 RGBA 色彩空间中对源项目进行着色。

源应用效果

叶子上的黑甲虫

应用了上色效果的甲虫

示例

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

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
    }

    Colorize {
        anchors.fill: bug
        source: bug
        hue: 0.0
        saturation: 0.5
        lightness: -0.2
    }
}

属性文档

cached : bool

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

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

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

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

hue : real

此属性定义用于为源对象着色的色相值。

该值的取值范围为 0.0 到 1.0。默认情况下,该属性设置为0.0 ,这会生成一种略带红色的颜色。

允许的色相值

显示色相值从 0.0 到 1.0 的色谱

不同色相值的输出示例

使用色相 0.2 对甲虫进行上色

使用色相 0.5 对甲虫进行上色

使用色相 0.8 对甲虫进行上色

色相:0.2 色相:0.5 色相:0.8
saturation: 1saturation: 1saturation: 1
lightness: 0lightness: 0lightness: 0

lightness : real

此属性定义了源像素的亮度值应增加或减少的幅度。

与色相和饱和度属性不同,明度属性并不设定具体数值,而是调整源像素的现有明度值。

该值的范围为 -1.0(降低)到 1.0(提高)。默认情况下,该属性设置为0.0 (无变化)。

不同明度值的输出示例

甲虫变暗,亮度 -0.75

亮度正常的甲虫

甲壳虫车身轻量化,轻量化程度为0.75

明度:-0.75 明度:0 明度:0.75
hue: 0hue: 0hue: 0
saturation: 1saturation: 1saturation: 1

saturation : real

此属性定义了用于为源素材着色的饱和度值。

该值范围为 0.0(去饱和)到 1.0(饱和)。默认情况下,该属性设置为1.0 (饱和)。

不同饱和度值的输出示例

Beetle 去饱和,饱和度为 0

饱和度为 0.5 的甲虫

甲虫完全饱和

饱和度:0 饱和度:0.5 饱和度:1
hue: 0hue: 0hue: 0
lightness: 0lightness: 0lightness: 0

source : variant

此属性定义了为该效果提供源像素的源项目。

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

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