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


}
相关推荐
XS0301068 分钟前
Java 基础(九) IO流
java·开发语言·php
Highcharts.js9 分钟前
用Highcharts如何动态向一个序列添加点
前端·javascript·react.js·highcharts
Teable任意门互动10 分钟前
多维表格哪家最好用最容易上手?国产开源 Teable 测评
开发语言·数据库·开源·excel·飞书·开源软件
独隅10 分钟前
此电脑网络位置异常的AD域排错指南
开发语言·php
陈天伟教授11 分钟前
GPT Image 2
开发语言·人工智能·架构
云泽80814 分钟前
二叉树高阶笔试算法题精讲(一):序列化、层序遍历、LCA 与 BST 转换
数据结构·c++·算法
HookJames15 分钟前
设计Section 09 · Cost & Lead Time Factors 的完整 Block Editor 操作步骤
前端
他是龙55119 分钟前
68:Java 原生反序列化 & SpringBoot 攻防
java·开发语言·spring boot
cen__y30 分钟前
Linux05(管道)
linux·运维·服务器·c语言·开发语言·文件流
6Hzlia31 分钟前
【Hot 100 刷题计划】 LeetCode 98. 验证二叉搜索树 | C++ 指针边界法
c++·算法·leetcode