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


}
相关推荐
A_aspectJ6 分钟前
【Java基础开发】 基于Swing GUI 组件实现图书管理系统
java·开发语言
GISer_Jing9 分钟前
Dify可视化编排:技术架构与实战指南
前端·人工智能·ai编程
牢姐与蒯16 分钟前
c++数据结构之二叉搜索树
数据结构·c++·搜索
宇宙realman_99916 分钟前
DSP28335-FlashAPI使用
linux·前端·python
xyq202420 分钟前
Font Awesome 加载中图标
开发语言
踩着两条虫41 分钟前
VTJ 平台六大设计模式落地实战指南
开发语言·前端·人工智能·低代码·设计模式·重构·架构
Yeats_Liao41 分钟前
后台 Sidebar 伸缩交互(PC + 移动端)实现
前端·javascript·css·html5
Morwit42 分钟前
【力扣hot100】 416. 分割等和子集
数据结构·c++·算法·leetcode·职场和发展
MXN_小南学前端1 小时前
computed 计算属性详解:触发时机、实战场景、Vue2 与 Vue3 对比
前端·javascript·vue.js
qeen871 小时前
【算法笔记】二分查找与二分答案
c语言·c++·笔记·学习·算法·二分