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

}
相关推荐
whisperrr.1 小时前
【JavaWeb12】数据交换与异步请求:JSON与Ajax的绝妙搭配是否塑造了Web的交互革命?
前端·ajax·json
烂蜻蜓2 小时前
前端已死?什么是前端
开发语言·前端·javascript·vue.js·uni-app
谢尔登3 小时前
Vue 和 React 的异同点
前端·vue.js·react.js
祈澈菇凉7 小时前
Webpack的基本功能有哪些
前端·javascript·vue.js
小纯洁w8 小时前
Webpack 的 require.context 和 Vite 的 import.meta.glob 的详细介绍和使用
前端·webpack·node.js
想睡好8 小时前
css文本属性
前端·css
qianmoQ8 小时前
第三章:组件开发实战 - 第五节 - Tailwind CSS 响应式导航栏实现
前端·css
zhoupenghui1688 小时前
golang时间相关函数总结
服务器·前端·golang·time
White graces9 小时前
正则表达式效验邮箱格式, 手机号格式, 密码长度
前端·spring boot·spring·正则表达式·java-ee·maven·intellij-idea
庸俗今天不摸鱼9 小时前
Canvas进阶-4、边界检测(流光,鼠标拖尾)
开发语言·前端·javascript·计算机外设