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


}
相关推荐
番茄去哪了1 分钟前
Java基础面试题day01
java·开发语言·后端·javase·八股·面向对象编程
wuqingshun3141596 分钟前
说说进程和线程的区别?
java·开发语言·jvm
前端小趴菜058 分钟前
vue3项目优化方案
前端·javascript·vue.js
Mr_Swilder9 分钟前
WebGPU 基础 (WebGPU Fundamentals)
前端
张3蜂22 分钟前
HTML5语义化标签:现代网页的骨架与灵魂
前端·html·html5
91刘仁德28 分钟前
C++ 内存管理
android·c语言·数据结构·c++·经验分享·笔记·算法
悟空瞎说34 分钟前
我用 PixiJS 撸了个圆桌会议选座系统,从 0 到 1 踩坑全复盘
前端
码云之上1 小时前
从 SPA 到全栈:AI 时代的前端架构升级实践
前端·架构·ai编程
Elastic 中国社区官方博客1 小时前
用于 Elasticsearch 的 Gemini CLI 扩展,包含工具和技能
大数据·开发语言·人工智能·elasticsearch·搜索引擎·全文检索
老赵的博客1 小时前
qwebengineview 锲入网页并关闭
c++