Qt_Note20_QML_自定义Grid控件与OpacityMask的使用

cpp 复制代码
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtGraphicalEffects 1.14

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")

    // 自定义Grid控件与OpacityMask的使用
    Grid {
        id: grid
        width: 15
        height: 200
        columns: 3
        x: 300
        y: 100
        visible: false  //看不到了
        Repeater {
//            model: grid.width / 5 * grid.height / 5
            model: grid.width / 5 * 200 / 5
            Rectangle {
                width: 5
                height: 5
                color: index % 2 ? "black" : "white"
                Component.onCompleted: {
                    console.log("rect" + index)
                }
            }
        }
    }

    Rectangle {
        id: maskRect
        x: 200
        y: 100
        width: grid.width
        height: grid.height
        visible: true
        radius: 10
        border.color: "red"
    }

    Button {
        width: 50
        height: 50
        x: 100
        y: 100
        onClicked: {
            grid.height -= 10
        }
    }

    Rectangle{
        width: grid.width + 4
        height: grid.height + 4
//        anchors.centerIn: parent
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottom: parent.bottom
        border.color: "red"
        radius: 10
        border.width: 3
        OpacityMask {
            source: grid
            maskSource: maskRect
            anchors.fill: parent
            anchors.margins: 2
        }
    }


}
相关推荐
心易行者2 分钟前
代码写好了,然后呢?——手把手教你把Python脚本变成能赚钱的Web应用
开发语言·前端·python
程序员蓝莓3 分钟前
别再花钱买HTTPS证书了!永久免费自动更新证书-Let's Encrypt。三步无脑安装。
前端
AKA__Zas3 分钟前
初识 事务
java·开发语言·数据库·sql
LinHan4 分钟前
功能区代码块一直不能优雅折叠?2026年,我终于用这个 VS Code 插件解决了
前端
kongba0075 分钟前
2026年4月19日 kimi记忆备份
java·前端·数据库
青天诀5 分钟前
mobile-bridge-mcp,实现AI远程操控手机上的web页面
前端
今儿敲了吗6 分钟前
常用UI组件
开发语言
零号全栈寒江独钓6 分钟前
基于c/c++实现linux/windows跨平台ntp时间戳服务器
linux·c语言·c++·windows
高斯林.神犇12 分钟前
六、java配置类改造ioc
java·开发语言
ulias21212 分钟前
进程初识(1)
linux·运维·服务器·网络·c++