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


}
相关推荐
excel3 分钟前
Vue SFC 样式变量机制源码深度解析:cssVarsPlugin 与编译流程
前端
excel6 分钟前
🧩 Vue 编译工具中的实用函数模块解析
前端
fpcc7 分钟前
c++23中的print和println
c++·c++23
excel9 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第五篇)
前端
程序猿_极客13 分钟前
【2025】16届蓝桥杯 Java 组全题详解(省赛真题 + 思路 + 代码)
java·开发语言·职场和发展·蓝桥杯
excel15 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第六篇 · 终篇)
前端
不吃香菜的猪18 分钟前
el-upload实现文件上传预览
前端·javascript·vue.js
excel23 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第四篇)
前端
excel28 分钟前
🧩 深入剖析 Vue 编译器中的 TypeScript 类型系统(第二篇)
前端
老夫的码又出BUG了31 分钟前
分布式Web应用场景下存在的Session问题
前端·分布式·后端