Qml——Rectangle元素
1.rectangle元素是用来绘制实心矩形Rectangle{ x: 30 y: 30 color: red //矩形填充色 width: 100 height: 100 border.color: green border.width: 5 radius: 20 //四个角的圆角半径 antialiasing: true //抗锯齿让圆角边缘平滑 rotation: 45 //相对元素中心点顺时针旋转45° }运行结果2.rectangle线性渐变gradient属性默认是从上往下渐变通过GrandientStop制定每个位置上的颜色例如Rectangle{ x: 30 y: 30 color: red //矩形填充色 width: 100 height: 100 radius: 20 gradient: Gradient{ GradientStop { position: 0.0; color: red} GradientStop { position: 0.5; color: yellow} GradientStop { position: 1.0; color: green} } }运行结果如果想要实现水平渐变、斜角渐变则要使用LinearGradient对象必须使用start和end属性来指定渐变的方向start: Qt.point(int x1, int y1) end: Qt.point(int x2, int y2)如果x1x2则表示垂直渐变如果y1y2则表示平行渐变如果都不相等则表示斜角线性渐变Rectangle{ x: 30 y: 30 color: red //矩形填充色 width: 100 height: 100 radius: 20 antialiasing: true; //抗锯齿 LinearGradient{ anchors.fill: parent //填满整个父元素 start: Qt.point(0, 0) end: Qt.point(parent.width, 0) gradient: Gradient{ GradientStop { position: 0.0; color: red} GradientStop { position: 0.5; color: yellow} GradientStop { position: 1.0; color: green} } } }运行结果圆锥渐变——ConicalGradient常用属性angle起始的顺时针角度位置horizontalOffset中心点水平偏移位置verticalOffset中心点垂直偏移位置