qml实现消息图片展示

匿名 (未验证) 提交于 2019-12-03 00:22:01

本文主要介绍如何展示不同大小尺寸的图片,并加上边框。实现步骤如下。

1、实现不同尺寸的图片的展示。主要运用OpacityMask实现圆角功能。

Rectangle {
    width: image_area.paintedWidth
    height: image_area.paintedHeight
    radius: 5
    property alias url: image_area.source
    property int size: 200
    Image {
        id: image_area
        sourceSize: Qt.size(size, size)
        smooth: true
        visible: false
    }
    Rectangle {
        id: mask_area
        anchors.fill: image_area
        radius: 5
        visible: false
    }
    OpacityMask {
        anchors.fill: image_area
        source: image_area
        maskSource: mask_area
    }
}

2、实现边框。边框通过RectangularGlow实现。

Item {
    width: rect.width
    height: rect.height
    property alias url: rect.url
    property alias size: rect.size
    RectangularGlow {
        id: effect
        anchors.fill: rect
        glowRadius: 2   // 边框宽度
        spread: 1       // 颜色是否渐进
        color: "#e0e0e0"    // 边框颜色
        cornerRadius: rect.radius + glowRadius
    }
    MyBorderImage {
        id: rect
    }
}


最终效果如图:

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!