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

}
相关推荐
layman052810 分钟前
vue中理解MVVM
前端·javascript·vue.js
一舍予1 小时前
八股文-js篇
开发语言·前端·javascript
鸡鸭扣2 小时前
DRF/Django+Vue项目线上部署:腾讯云+Centos7.6(github的SSH认证)
前端·vue.js·python·django·腾讯云·drf
龙井茶Sky2 小时前
验证码与登录过程逻辑学习总结
前端·登录·验证码
2401_831943323 小时前
Element Plus对话框(ElDialog)全面指南:打造灵活弹窗交互
前端·vue.js·交互
strongwyy3 小时前
DA14585墨水屏学习(2)
前端·javascript·学习
好青崧4 小时前
冒泡排序的原理
前端
椒盐螺丝钉4 小时前
CSS 基础知识分享:从入门到注意事项
前端·css
冬阳春晖4 小时前
web animation API 锋利的css动画控制器 (更新中)
前端·javascript·css
Python私教5 小时前
使用FastAPI和React以及MongoDB构建全栈Web应用05 FastAPI快速入门
前端·react.js·fastapi