一个格子条,点击缩短
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
}
}
}