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


}
相关推荐
炘爚6 分钟前
C++实现分布式集群聊天服务器
服务器·c++·分布式
踩着两条虫9 分钟前
VTJ.PRO 新手入门:从环境搭建到 AI 生成首个 Vue3 应用
前端·javascript·数据库·vue.js·人工智能·低代码
十有八七10 分钟前
Resume Agent P1 开发 — 记忆管理 + 用户配置 + 工具系统
前端·后端
低频电磁之道15 分钟前
C++中 explicit 用法:多参数构造函数
c++
他是龙55118 分钟前
63:JS 加密断点调试与逆向实战
开发语言·javascript·状态模式
常利兵20 分钟前
Kotlin类型魔法:Any、Unit、Nothing 深度探秘
android·开发语言·kotlin
莫逸风24 分钟前
【java-core-collections】红黑树深度解析
java·开发语言
2601_9498161625 分钟前
Node.js npm 安装过程中 EBUSY 错误的分析与解决方案
前端·npm·node.js
Ulyanov37 分钟前
《玩转QT Designer Studio:从设计到实战》 QT Designer Studio入门实战:智能登录系统开发
开发语言·python·qt·雷达电子对抗
pancakenut38 分钟前
自定义属性:从html到react
前端