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 分钟前
【C++】动态内存管理
开发语言·c++
uhakadotcom9 分钟前
开源:subdomainpy快速高效的 Python 子域名检测工具
前端·后端·面试
一只鲲12 分钟前
40 C++ STL模板库9-容器2-vector
开发语言·c++
爱加班的猫17 分钟前
Node.js 中 require 函数的原理深度解析
前端·node.js
用户81651112639718 分钟前
WWDC 2025 Build a SwiftUI app with the new design
前端
伍哥的传说22 分钟前
Vue 3.5重磅更新:响应式Props解构,让组件开发更简洁高效
前端·javascript·vue.js·defineprops·vue 3.5·响应式props解构·vue.js新特性
励志不掉头发的内向程序员24 分钟前
C++基础——内存管理
开发语言·c++
阅文作家助手开发团队_山神25 分钟前
第一章: Mac Flutter Engine开发准备工作
前端·flutter
菜牙买菜27 分钟前
Hicharts入门
前端·vue.js·数据可视化