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


}
相关推荐
techdashen几秒前
Go 1.18+ slice 扩容机制详解
开发语言·后端·golang
Mintopia2 分钟前
🌌 信任是否会成为未来的货币?
前端·人工智能·aigc
fqbqrr3 分钟前
2601C++,模块导出分类
前端·c++
froginwe115 分钟前
R 包:全面解析与高效使用指南
开发语言
倚栏听风雨8 分钟前
vscode 运用 ts 代码需要准备什么
前端
zero.cyx8 分钟前
javaweb(AI)-----后端
java·开发语言
say_fall15 分钟前
泛型编程基石:C++ 模板从入门到熟练
java·开发语言·c++·编辑器·visual studio
韩曙亮16 分钟前
【Web APIs】浏览器本地存储 ① ( window.sessionStorage 本地存储 | window.localStorage 本地存储 )
服务器·前端·javascript·本地存储·localstorage·sessionstorage·web apis
吃杠碰小鸡18 分钟前
前端Mac快速搭建开发环境
前端·macos
txinyu的博客21 分钟前
结合游戏场景解析UDP可靠性问题
java·开发语言·c++·网络协议·游戏·udp