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

}
相关推荐
humors2211 分钟前
前端开发案例(不定期更新)
前端·vue.js·elementui·ruoyi·若依
菠萝+冰3 分钟前
npm中-d -g 和默认安装的区别
前端·npm·node.js
一路向北North37 分钟前
网页版预编译SQL转换工具
前端·javascript·sql
拿不拿铁192 小时前
Vite 5.x 开发模式启动流程分析
前端
fruge2 小时前
设计稿还原技巧:解决间距、阴影、字体适配的细节问题
前端·css
BBB努力学习程序设计2 小时前
了解响应式Web设计:viewport网页可视区域
前端·html
zhangyao9403302 小时前
uni-app scroll-view特定情况下运用
前端·javascript·uni-app
码农张2 小时前
从原理到实践,吃透 Lit 响应式系统的核心逻辑
前端
jump6802 小时前
object和map 和 WeakMap 的区别
前端
打小就很皮...2 小时前
基于 Dify 实现 AI 流式对话:组件设计思路(React)
前端·react.js·dify·流式对话