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


}
相关推荐
镜宇秋霖丶20 小时前
常驻大哥24分法,记得看
前端·javascript·vue.js
王老师青少年编程20 小时前
csp信奥赛C++高频考点专项训练之字符串 --【字符统计】:「MYOI-R3」字符串
c++·字符串·csp·高频考点·信奥赛·专项训练·「myoi-r3」字符串
心连欣20 小时前
跨越时代的对话:Vue 2 与 Vue 3 的终极对决与环境搭建指南
前端·javascript·vue.js
无限进步_20 小时前
简单聊聊 C++ 中的 unordered_map 和 unordered_set
c语言·开发语言·数据结构·c++·windows·哈希算法·散列表
LNN202220 小时前
半导体设备 UI 开发工程师:完整工作执行手册
开发语言·python·ui
ch.ju20 小时前
Java Programming Chapter 2-Nested call
java·开发语言
Csvn21 小时前
Vue Router 实战
前端·vue.js
yqcoder21 小时前
JavaScript 内存揭秘:堆(Heap) vs 栈(Stack)
开发语言·javascript·ecmascript
覆东流21 小时前
第11天:python字典基础
开发语言·后端·python
河阿里21 小时前
深入理解LRU缓存机制:从原理到应用(C++实现
开发语言·c++·缓存