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


}
相关推荐
柏木乃一5 小时前
库的制作与原理(2)ELF格式,程序地址空间part2,程序加载
linux·服务器·c++·进程·elf··进程地址空间
羑悻的小杀马特5 小时前
Elasticsearch + Kibana 实战指南:从安装部署到 C++ 客户端封装,解锁搜索引擎开发核心技能
c++·elasticsearch·搜索引擎·kibana
杜子不疼.5 小时前
【Linux】基础IO(三):文件描述符与重定向
linux·c语言·开发语言·人工智能
时见先生12 小时前
Python库和conda搭建虚拟环境
开发语言·人工智能·python·自然语言处理·conda
我是伪码农12 小时前
Vue 1.23
前端·javascript·vue.js
a努力。12 小时前
国家电网Java面试被问:混沌工程在分布式系统中的应用
java·开发语言·数据库·git·mysql·面试·职场和发展
Yvonne爱编码12 小时前
Java 四大内部类全解析:从设计本质到实战应用
java·开发语言·python
wqwqweee12 小时前
Flutter for OpenHarmony 看书管理记录App实战:搜索功能实现
开发语言·javascript·python·flutter·harmonyos
yongui4783413 小时前
基于MATLAB的NALM锁模光纤激光器仿真实现
开发语言·matlab
-To be number.wan14 小时前
Python数据分析:numpy数值计算基础
开发语言·python·数据分析