本页内容

DirectionalBlur QML Type

对指定方向应用模糊效果。更多...

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

Item

属性

详细说明

该效果会营造出源对象似乎正朝着模糊方向移动的视觉印象。模糊效果会作用于每个像素的两侧,因此将方向设置为 0 或 180 都会产生相同的效果。

其他可用的运动模糊效果包括ZoomBlur 和RadialBlur 。

源已应用的效果

叶子上的黑甲虫

应用了方向性模糊效果的甲虫

注意:此 效果仅在 OpenGL 运行时可用。

示例

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

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
    }

    DirectionalBlur {
        anchors.fill: bug
        source: bug
        angle: 90
        length: 32
        samples: 24
    }
}

属性文档

angle : real

此属性定义了模糊的方向。模糊效果会作用于每个像素的两侧,因此将方向设置为 0 和 180 会产生相同的结果。

该值的取值范围为 -180.0 到 180.0。默认情况下,该属性设置为0.0 。

不同角度值的输出示例

角度为0时的水平模糊

45度角的对角线模糊

90度角的垂直模糊

角度:0.0 angle: 45.0 angle: 90.0
samples: 24samples: 24samples: 24
length: 32length: 32length: 32

cached : bool

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

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

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

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

length : real

此属性定义了每个像素所感知到的位移量。该位移会均匀地分配到每个像素的两侧。

模糊效果的质量取决于samples 属性。如果length值较大,则需要更多的采样点才能保持较高的视觉质量。

该值的取值范围为 0.0 到 inf。默认情况下,该属性设置为0.0 (无模糊)。

不同长度值下的输出示例

没有模糊的甲虫

甲虫,模糊长度适中

模糊长度最大的甲虫

length:0.0 length:32.0 length: 48.0
samples: 24samples: 24samples: 24
angle: 0angle: 0angle: 0

samples : int

该属性定义了在进行模糊计算时,每个像素会采样多少次。数值越大,效果越好,但渲染速度会变慢。

该属性不适用于动画效果。更改此属性可能会导致底层的 OpenGL 着色器被重新编译。

允许的取值范围为 0 到 inf(实际最大值取决于 GPU)。默认情况下,该属性设置为0 (不进行采样)。

source : variant

此属性用于指定将被模糊处理的源项目。

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

transparentBorder : bool

该属性定义了项目边缘附近的模糊行为,此时像素的模糊效果会受到源边缘外部像素的影响。

如果将该属性设置为true ,则源区域外的像素将被解释为透明,这类似于 OpenGL 的“clamp-to-border”扩展。模糊效果会稍微扩展到效果项区域之外。

如果将该属性设置为false ,则源区域外的像素将被解释为与项目边缘像素具有相同的颜色,这类似于 OpenGL 的“clamp-to-edge”行为。模糊效果不会扩展到效果项目区域之外。

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

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