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


}
相关推荐
游乐码13 分钟前
c#类和对象
开发语言·c#
黎雁·泠崖28 分钟前
Java常用类核心详解(一):Math 类超细讲解
java·开发语言
懒惰成性的1 小时前
12.Java的异常
java·开发语言
-To be number.wan1 小时前
Python数据分析:时间序列数据分析
开发语言·python·数据分析
装不满的克莱因瓶1 小时前
Java7新特性:try-with-resources写法
java·前端·javascript·jdk·新特性·jdk7
前路不黑暗@1 小时前
Java项目:Java脚手架项目的通用组件的封装(六)
java·开发语言·spring
马士兵教育2 小时前
程序员简历如何编写才能凸显出差异化,才能拿到更多面试机会?
开发语言·后端·面试·职场和发展·架构
SailingCoder2 小时前
【 从“打补丁“到“换思路“ 】一次企业级 AI Agent 的架构拐点
大数据·前端·人工智能·面试·架构·agent
jz_ddk2 小时前
[指南] Python循环语句完全指南
开发语言·python·continue·循环·for·while·break
chilavert3182 小时前
技术演进中的开发沉思-368:锁机制(中)
java·开发语言·jvm