Pyside6/PyQt6中QML一些特殊实现搜集以及总结

PyQt6或PySide6无法实现的Qt5的特效

Qt5中图片的一些专属特效

Qt5图片圆角特效

需要先导入模块

import Qt5Compat.GraphicalEffects

在图片Image里面添加:

layer.enabled: true
layer.effect: OpacityMask {
    maskSource: Rectangle {
        // 此处image为Image的ID
        width: image.width
        height: image.height
        radius: 20  // 圆角的大小
        color: "black"  // 不透明
    }
}


>>>完整代码参考<<<

import Qt5Compat.GraphicalEffects

// 背景图片 ============================================
Image {
    id: back_imgs
    // 拉伸保持 ----------------------------------------
    anchors.fill: parent
    fillMode: Image.PreserveAspectCrop  // 保持图片比例
    // 使用圆角 ----------------------------------------
    layer.enabled: true
    layer.effect: OpacityMask {
        maskSource: Rectangle {
            color: "black"  // 不透明
            height: back_imgs.height
            radius: 20  // 圆角的大小
            width: back_imgs.width
        }
    }
    // 图片内容 ----------------------------------------
    source: "qrc:/example/res/image/PageItem-Banner.jpg"
}

Last modification:February 19, 2024
If you think my article is useful to you, please feel free to appreciate