Qt_Note20_QML_自定义Grid控件与OpacityMask的使用

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


}

在这里插入图片描述

相关推荐

  1. Android:定义

    2024-04-06 21:22:01       29 阅读
  2. QT中如何使用定义

    2024-04-06 21:22:01       45 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-06 21:22:01       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-06 21:22:01       20 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-06 21:22:01       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-06 21:22:01       20 阅读

热门阅读

  1. 第十四届蓝桥杯省赛大学B组(C/C++)整数删除

    2024-04-06 21:22:01       22 阅读
  2. 抖音运营技巧2

    2024-04-06 21:22:01       24 阅读
  3. MyBatis plus 详解

    2024-04-06 21:22:01       56 阅读
  4. 谈谈Python中的正则表达式及其用法。

    2024-04-06 21:22:01       22 阅读
  5. 在MacOS上安装Homebrew:初学者指南

    2024-04-06 21:22:01       28 阅读
  6. js的some函数

    2024-04-06 21:22:01       21 阅读
  7. 【面经】3月29日 美团/美团平台/后端/一面/1h

    2024-04-06 21:22:01       19 阅读
  8. tomcat 知多少

    2024-04-06 21:22:01       18 阅读