QML-Grid和OpacityMask

一个格子条,点击缩短

cpp 复制代码
import QtQuick 2.0
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
//导入
import QtGraphicalEffects 1.12

Window {
    id:window
    width: 600
    height: 500
    color: "white"
    visible: true

    Grid {
        visible: false
        id:grid
        width:405
        height: 15
//        columns: 81
        rows: 3
        x:300
        y:100
        //网格子
        Repeater{
            model: 405/5*15/5
            Rectangle{
                width: 5
                height: 5
                color: index % 2 ? "black":"white"
            }
        }
    }
    Rectangle{
        visible: false
        id:maskRect
        width: grid.width
        height: grid.height
        radius: 10
        border.color: "black"
    }

    Rectangle{
        width: grid.width+5
        height: grid.height+5
        radius: 10
        color: "red"
        //绝对居中
//        anchors.centerIn: parent
        //水平居中
//        anchors.horizontalCenter: parent.horizontalCenter
        //竖直居中
        anchors.verticalCenter: parent.verticalCenter
        //固定在一侧
        anchors.left: parent.left

        OpacityMask {
            source: grid
            maskSource: maskRect
            anchors.fill: parent
            anchors.margins: 2
        }
    }

    Button{
        width: 50
        height: 50

        onClicked: {
            grid.width-=10
        }
    }

}
相关推荐
小码哥_常5 分钟前
Room 3.0:移动端持久化的“重生”变革
前端
Front思1 小时前
前端的.hbs
前端
_.Switch1 小时前
东方财富股票数据JS逆向:secids字段和AES加密实战
开发语言·前端·javascript·网络·爬虫·python·ecmascript
软件技术NINI1 小时前
webkit简介及工作流程
开发语言·前端·javascript·udp·ecmascript·webkit·yarn
普通网友1 小时前
ES6模块化、Promise、async、await、EventLoop、API接口案例_export function 与 await
前端·ecmascript·es6
難釋懷1 小时前
Vue混入
前端·javascript·vue.js
若梦plus1 小时前
TypeScript进阶
前端·javascript·typescript·ecmascript
直奔標竿1 小时前
Java开发者AI转型第二十七课!Spring AI 个人知识库实战(六)——全栈闭环收官,解锁前端流式渲染终极技巧
java·开发语言·前端·人工智能·后端·spring
@PHARAOH2 小时前
WHAT - cursor cli 开发范式
前端·ai·ai编程
子兮曰3 小时前
深入 HTML-in-Canvas:当 Canvas 学会了渲染 DOM,前端图形生态要变天了
前端·javascript·canvas