1、概述
源码放在文章末尾

该项目实现了图像的发光效果,特别适合做头像,项目demo演示如下所示:
《QT实用小工具·四十二》圆形发光图像-LMLPHP

项目部分代码如下所示:

import QtQuick 2.7
import QtGraphicalEffects 1.12

Item
{
    id: root
    width: 80
    height: 80

    property int radius: width >> 1;    //默认宽度的一半
    property alias source: image.source;
    property alias mipmap: image.mipmap;
    property alias fillMode: image.fillMode;

    Image
    {
        id: image
        sourceSize: Qt.size(parent.width, parent.height)
        mipmap: true
        visible: false
    }

    Rectangle
    {
        id: mask
        anchors.fill: parent
        radius: root.radius
        visible: false
    }

    OpacityMask
    {
        anchors.fill: parent
        source: image
        maskSource: mask
    }
}

源码下载

04-26 01:03