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


}
相关推荐
myloveasuka29 分钟前
Java与C++多态访问成员变量/方法 对比
java·开发语言·c++
C澒36 分钟前
微前端容器标准化:公共能力标准化
前端·架构
2301_8217005340 分钟前
C++编译期多态实现
开发语言·c++·算法
Setsuna_F_Seiei44 分钟前
AI 对话应用之 JS 的流式接口数据处理
前端·javascript·ai编程
奥地利落榜美术生灬1 小时前
c++ 锁相关(mutex 等)
开发语言·c++
xixihaha13241 小时前
C++与FPGA协同设计
开发语言·c++·算法
重庆小透明1 小时前
【java基础篇】详解BigDecimal
java·开发语言
ID_180079054731 小时前
模拟1688商品详情的Python API实现,返回符合风格的JSON数据
开发语言·python·json
青柠代码录1 小时前
【Vue3】Vue Router 4 路由全解
前端·vue.js
小小怪7501 小时前
C++中的函数式编程
开发语言·c++·算法