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


}
相关推荐
程序员海军几秒前
AI 越来越强,为什么打工人反而越来越累、越来越内耗了?
前端·程序员·aigc
名字还没想好☜8 分钟前
Java NIO ByteBuffer 实战:flip/clear/compact 三个绕晕人的方法与 position/limit 心智模型
java·开发语言·后端·spring·nio
晴天1613 分钟前
VSCodium 项目介绍
前端·javascript·vscode
世岩清上17 分钟前
展厅数字内容同质化严重,怎样打造专属叙事风格?
大数据·前端·javascript·人工智能·html·音视频·展厅改造
晴天1620 分钟前
前端动画体系全解析:类型、实现方案与工程选型最佳实践
前端
小溪学编程35 分钟前
AQS 原理详解:从 CLH 队列到 ReentrantLock 的实现
java·开发语言
David猪大卫36 分钟前
【C++修炼】哈希表的实现
数据结构·c++·笔记·学习·算法·哈希算法·散列表
持敬chijing37 分钟前
Web前后端开发-JavaScript 入门教程
开发语言·前端·javascript
李高钢38 分钟前
Python Django 框架入门:从零搭建你的第一个 Web 应用
前端·python·django
PC2005_cloud41 分钟前
Rust学习笔记:所有权、借用与生命周期——Rust的核心机制
前端·后端