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
        }
    }


}
相关推荐
大鹏说大话14 小时前
Kotlin vs Java:Android之外,后端开发该怎么选?
开发语言
念你那丝微笑14 小时前
2026年Vue前端面试准备
前端·vue.js·面试
冴羽yayujs14 小时前
GitHub 前端热榜项目 - 日榜(2026-05-09)
前端·github
Copy_Paste_Coder14 小时前
小程序失败后,换个方向,终于成功搞到收益
前端·javascript·后端
skywalker_1114 小时前
注解和反射
java·开发语言
爱代码的小黄人14 小时前
总谐波畸变率 THD 的计算公式整理:MATLAB 官方公式与论文常用公式对比
开发语言·matlab
云深麋鹿14 小时前
C++ | AVLTree
开发语言·c++
2zcode14 小时前
基于Matlab不规则颗粒粒径周长面积测量及计数系统
开发语言·算法·matlab
XerCis14 小时前
ngrok实现内网穿透(以Python FastAPI为例)
开发语言·python·fastapi·ngrok
Qt程序员14 小时前
从协议到实战:HTTP 反向代理
linux·c++·websocket·nginx·http·反向代理·正向代理