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


}
相关推荐
伯远医学3 分钟前
RIP-seq 高分文献案例分享
java·前端·javascript·人工智能·算法·eclipse·html
hunterandroid4 分钟前
[鸿蒙从零到一] LazyForEach 复用陷阱与 KeyGenerator 设计实战
前端
张张的快乐时光呀!6 分钟前
MFC添加类向导并实现响应
c++·mfc
Hilaku10 分钟前
Web Components 为什么火不起来?
前端·javascript·程序员
Liora_Yvonne15 分钟前
从数据库到 Vue 页面:用 LY Fullstack 完成第一个真实全栈业务模块
前端·后端·nestjs
问君能有几多愁~18 分钟前
Qt Json 序列化操作
开发语言·qt·json
hunterandroid20 分钟前
自定义 View 绘制与触摸冲突:从滑动卡顿到事件分发闭环
android·前端
平常心的技术小牛21 分钟前
Qt-快速上手-QFileDialog
windows·qt·microsoft
vancece24 分钟前
JS实现堆 & 215.数组中的第K个最大元素
java·前端·javascript
xieliyu.25 分钟前
MySQL 进阶笔记:用户 / 会话 / 全局 / 局部变量 + CASE 分支语法
开发语言·数据库·笔记·mysql