Qml and image blur

I want to achieve a blur effect using QML. I found links to "effect: blur" (example) , but in Qt 4.8 this does not work. As far as I know, this is implemented with C ++ code. But how?

+5
source share
2 answers

An attribute effectthat has all the visual elements of QML accepts all effects that are subclasses QGraphicsEffect. Qt 4.8 comes with QGraphicsBlurEffect, QGraphicsColorizeEffect, QGraphicsDropShadowEffectand QGraphicsOpacityEffect. Initially, they were available in QML by default, but at one time in development (prior to the first public release of QtQuick) they were excluded for performance reasons. To make them work again, you need to include the following lines of code in the C ++ part of its application, for example, in a function main:

qmlRegisterType<QGraphicsBlurEffect>("Effects",1,0,"Blur");
qmlRegisterType<QGraphicsColorizeEffect>("Effects",1,0,"Colorize");
qmlRegisterType<QGraphicsDropShadowEffect>("Effects",1,0,"DropShadow");
qmlRegisterType<QGraphicsOpacityEffect>("Effects",1,0,"OpacityEffect");

This makes these classes available for QML, so they can be used as:

import QtQuick 1.1
import Effects 1.0

Item {
    // [...]
    effect: Blur {
        blurRadius: 10.0
    }
}

, . ShaderEffectItem. , GLSL, GPU, , QGraphicsEffect.

+13

, , : Qt Shader Effects. , GPU-, QML, .

+1

All Articles