Image rounded corners in QML

前端 未结 7 1090
遇见更好的自我
遇见更好的自我 2020-12-14 06:25

To my surprise, the Image component has no radius property. I tried emulating the rounded corners by putting the image in a rounded Rectangle

7条回答
  •  悲&欢浪女
    2020-12-14 06:33

    I know I'm a little late to the party, but I got here by googling, so thought I'd help future generations :) QtGraphicalEffects OpacityMask should do this a bit more simply (I had issues with the layer effect approach)

    Image {
        id: imgAuthor
    
        width: 64
        height: 64
    
        source: "qrc:/res/sample_avatar.jpg"
    
        visible: false // this is needed or the corners of the image will be visible underneath the opacity mask
    }
    
    OpacityMask {
        anchors.fill: imgAuthor
        source: imgAuthor
        maskSource: Rectangle {
            width: imgAuthor.width
            height: imgAuthor.height
            radius: 8
            visible: false // this also needs to be invisible or it will cover up the image
        }
    }
    

提交回复
热议问题