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


}
相关推荐
雨落在了我的手上8 分钟前
初始java(十七):常⽤⼯具类介绍
java·开发语言
无风听海10 分钟前
Bearer Token 权威指南:从原理到生产级安全实践
前端·javascript·安全
jerrywus16 分钟前
别只换模型!Claude Opus 4.8 努力控制 + Fast模式,真实能省钱3倍
前端·agent·claude
凤凰院凶涛QAQ19 分钟前
《Java版数据结构 & 集合类剖析》集合框架的封装设计与顺序表:“从 Iterable 到 ArrayList:集合框架的‘职业树“
java·开发语言·数据结构
riuphan19 分钟前
JavaScript 类型判断完全指南
前端·javascript
大菜菜小个子20 分钟前
偏特化(Partial Specialization)理解
c++
Hilaku26 分钟前
前端工程师最终会变成 AI工程师?
前端·javascript·程序员
yeflx30 分钟前
Ubuntu22.04重装显卡驱动
前端·chrome
吴可可12331 分钟前
Win7上开发CAD2004自定义实体全解析
c++·算法
孟华苏33 分钟前
怎么快速排查内存泄漏问题
java·开发语言·python