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


}
相关推荐
Yupureki2 分钟前
《算法竞赛从入门到国奖》算法基础:数据结构-并查集
c语言·数据结构·c++·算法
Andy4 分钟前
Cpp语法1
c++·c
前端小D5 分钟前
面向对象编程
开发语言·javascript
艾莉丝努力练剑12 分钟前
静态地址重定位与动态地址重定位:Linux操作系统的视角
java·linux·运维·服务器·c语言·开发语言·c++
从文处安18 分钟前
「前端何去何从」一直写 Vue ,为何要在 AI 时代去学 React「2」?
前端·react.js
葡萄城技术团队19 分钟前
Playwright 官方推荐的 Fixture 模式,为什么大厂架构师却在偷偷弃用?
前端
newbe3652421 分钟前
ImgBin CLI 工具设计:HagiCode 图片资产管理方案
前端·后端
bluceli23 分钟前
CSS Scroll Snap:打造丝滑滚动体验的利器
前端·css
www_stdio25 分钟前
深入理解 React Fiber 与浏览器事件循环:从性能瓶颈到调度机制
前端·react.js·面试
工边页字29 分钟前
LLM 系统设计核心:为什么必须压缩上下文?有哪些工程策略
前端·人工智能·后端