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


}
相关推荐
egoist202343 分钟前
【C++指南】一文总结C++类和对象【下】
c++·编辑器·类和对象·初始化列表·友元·匿名对象·c++ 11
恋恋风辰3 小时前
QT系列教程(16) 定时器事件
开发语言·qt·命令模式
kill bert4 小时前
第27周JavaSpringboot电商进阶开发 1.企业级用户验证
java·前端·数据库
SNAKEpc121385 小时前
Qt开源控件库(qt-material-widgets)的编译及使用
c++·qt·开源
拓端研究室TRL6 小时前
R软件线性模型与lmer混合效应模型对生态学龙类智力测试数据层级结构应用
开发语言·r语言
answerball6 小时前
🔥 Vue3响应式源码深度解剖:从Proxy魔法到依赖收集,手把手教你造轮子!🚀
前端·响应式设计·响应式编程
于慨7 小时前
计算机考研C语言
c语言·开发语言·数据结构
GGGGGGGGGGGGGG.7 小时前
使用dockerfile创建镜像
java·开发语言
请为小H留灯7 小时前
Python中很常用的100个函数整理
开发语言·python
Slow菜鸟7 小时前
ES5 vs ES6:JavaScript 演进之路
前端·javascript·es6