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


}
相关推荐
2501_911088231 分钟前
C++中的代理模式变体
开发语言·c++·算法
无限进步_3 分钟前
【C++】只出现一次的数字 III:位运算的巧妙应用
数据结构·c++·git·算法·leetcode·github·visual studio
cxxcode3 分钟前
ArrayBuffer / TypedArray / Blob / File 关系与操作指南
前端
2401_900151546 分钟前
代码覆盖率工具实战
开发语言·c++·算法
bu_shuo8 分钟前
在命令行中编译cpp文件
开发语言·c++·cpp
We་ct18 分钟前
React 更新触发原理详解
开发语言·前端·javascript·react.js·面试·前端框架·react
王的宝库18 分钟前
Go 语言:结构体:定义、初始化、方法、组合、Tag、对齐
开发语言·后端·学习·golang
落日漫游22 分钟前
Zabbix监控实战:Linux主机全流程配置
运维·开发语言·自动化
带娃的IT创业者22 分钟前
Python 异步编程完全指南(二):深入 asyncio 核心概念
开发语言·python·协程·事件循环·asyncio·异步编程