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


}
相关推荐
风味蘑菇干9 分钟前
使用接口定义规范,实现类完成具体逻辑。
java·开发语言
MATLAB代码顾问10 分钟前
【智能优化】无穷优化算法(INFO)原理与Python实现
开发语言·python·算法
Bruce_kaizy13 分钟前
c++ linux环境编程——从应用层到linux内核深入了解文件io的调用机制(爆肝)
linux·c++·c·嵌入式linux·文件io
2401_8332693018 分钟前
Java多线程:从入门到进阶
java·开发语言
z2005093020 分钟前
C++中的右值引用
开发语言·c++
SilentSamsara21 分钟前
迭代器协议:`__iter__` / `__next__` 的完整执行流程
开发语言·人工智能·python·算法·机器学习
平凡但不平庸的码农25 分钟前
Go Channel详解
开发语言·后端·golang
村上小树28 分钟前
非常简单地学习一下shareDB的原理
前端·javascript
认真的薛薛28 分钟前
阿里云: A记录 & CNAME
服务器·前端·阿里云
laomocoder29 分钟前
Project-Nexus-WAN-跨公网Agent对话
开发语言·php