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

}
相关推荐
工藤新一¹1 分钟前
《操作系统》第一章(1)
java·服务器·前端
用户9714171814271 分钟前
Flex 和 Grid 详细使用指南:从入门到实战避坑
前端·css
不会敲代码13 分钟前
使用 Mock.js 模拟 API 数据,实现前后端并行开发
前端·javascript
琛説4 分钟前
Web-Rooter:一种 IR + Lint 模式的 AI Agent 创新尝试【或许是下一个 AI 爆火方向】
前端·人工智能
用户97141718142715 分钟前
absolute 元素的包含块(containing block)怎么找
前端·css
青山Coding18 分钟前
Cesium应用(四):全球台风气象可视化实现
前端·vue.js·cesium
kyriewen18 分钟前
响应式设计:一套代码,手机平板电脑全拿下
前端·css·html
姝然_952719 分钟前
Jetpack Compose Shape 基础使用
前端
cxxcode24 分钟前
ArrayBuffer / TypedArray / Blob / File 关系与操作指南
前端