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 分钟前
C#异步开发探微
开发语言·c#
奇树谦1 分钟前
3-5年工控上位机(C++/Qt)面试题|聚焦实战,直击核心模块
c++·qt
2301_793804694 分钟前
C++中的访问者模式变体
开发语言·c++·算法
2501_945424808 分钟前
模板代码版本兼容
开发语言·c++·算法
WaywardOne9 分钟前
iOS复习必看!weak关键字底层原理(Deepseek&豆包)回答整理
前端
工边页字9 分钟前
AI公司面试100%加分的话题:如何做 API成本预算
前端·后端·面试
m0_5180194811 分钟前
C++中的委托构造函数
开发语言·c++·算法
m0_7434703713 分钟前
高性能计算框架实现
开发语言·c++·算法
weixin_3077791313 分钟前
2025年中国研究生数学建模竞赛A题:通用神经网络处理器下的核内调度问题——解决方案与实现
开发语言·人工智能·python·数学建模·性能优化
焦糖玛奇朵婷14 分钟前
盲盒小程序开发|解锁开箱新体验[特殊字符]
大数据·开发语言·程序人生·小程序·软件需求