Rectangle QML Type
A filled rectangle with an optional border. More...
Import Statement: | import QtQuick.Studio.Components 1.0 |
Since: | QtQuick.Studio.Components 1.0 |
Inherits: |
Properties
- bottomLeftRadius : int
- bottomRightRadius : int
- dashOffset : ShapePath
- dashPattern : ShapePath
- fillColor : ShapePath
- gradient : ShapePath
- radius : int
- strokeColor : ShapePath
- strokeStyle : ShapePath
- strokeWidth : ShapePath
- topLeftRadius : int
- topRightRadius : int
Detailed Description
Rectangle items are used to fill areas with solid color or gradients and to provide a rectangular border.
Each Rectangle item is painted using either a solid fill color, specified using the fillColor property, or a gradient, defined using one of the ShapeGradient subtypes and set using the gradient property. If both a color and a gradient are specified, the gradient is used.
An optional border can be added to a rectangle with its own color and thickness by setting the strokeColor and strokeWidth properties. Setting the color to transparent
creates a border without a fill color.
Rounded rectangles can be drawn using the radius property. The radius can also be specified separately for each corner. Because this introduces curved edges to the corners of a rectangle, it may be appropriate to set the antialiasing
property that is inherited from Item to improve the appearance of the rectangle.
Example Usage
You can use the Rectangle component in Qt Design Studio to create different kinds of rectangles.
The QML code looks as follows:
RectangleItem { id: rectangle gradient: RadialGradient { focalRadius: 0 centerY: 38.5 focalY: 38.5 centerX: 51.5 centerRadius: 38.5 GradientStop { position: 0 color: "#ffffff" } GradientStop { position: 1 color: "#000000" } focalX: 51.5 } bottomRightRadius: 0 topLeftRadius: 0 strokeColor: "gray" } RectangleItem { id: rectangle1 gradient: LinearGradient { y1: 0 y2: 77 x2: 103 x1: 0 GradientStop { position: 0 color: "#ffffff" } GradientStop { position: 1 color: "#000000" } } topRightRadius: 0 bottomLeftRadius: 0 strokeColor: "#808080" } RectangleItem { id: rectangle2 topLeftRadius: 0 bottomRightRadius: 0 fillColor: "#d3d3d3" strokeColor: "#808080" } RectangleItem { id: rectangle3 fillColor: "#000000" gradient: LinearGradient { y1: 0 y2: 77 x2: 103 x1: 0 GradientStop { position: 0 color: "#000000" } GradientStop { position: 1 color: "#fdf9f9" } } topRightRadius: 0 bottomLeftRadius: 0 strokeColor: "#808080" }
Property Documentation
bottomLeftRadius : int |
The radius of the bottom left rectangle corner.
bottomRightRadius : int |
The radius of the bottom right rectangle corner.
dashOffset : ShapePath |
The starting point of the dash pattern for the rectangle border.
The offset is measured in terms of the units used to specify the dash pattern. For example, a pattern where each stroke is four units long, followed by a gap of two units, will begin with the stroke when drawn as a line. However, if the dash offset is set to 4.0, any line drawn will begin with the gap. Values of the offset up to 4.0 will cause part of the stroke to be drawn first, and values of the offset between 4.0 and 6.0 will cause the line to begin with part of the gap.
The default value is 0.
See also QPen::setDashOffset().
dashPattern : ShapePath |
The dash pattern of the rectangle border specified as the dashes and the gaps between them.
The dash pattern is specified in units of the pen's width. That is, a dash with the length 5 and width 10 is 50 pixels long.
The default value is (4, 2), meaning a dash of 4 * strokeWidth pixels followed by a space of 2 * strokeWidth pixels.
See also QPen::setDashPattern().
fillColor : ShapePath |
The rectangle fill color.
A gradient for the fill can be specified by using gradient. If both a color and a gradient are specified, the gradient is used.
When set to transparent
, no filling occurs.
The default value is white
.
gradient : ShapePath |
The gradient of the rectangle fill color.
By default, no gradient is enabled and the value is null. In this case, the fill uses a solid color based on the value of fillColor.
When set, fillColor is ignored and filling is done using one of the ShapeGradient subtypes.
Note: The Gradient type cannot be used here. Rather, prefer using one of the advanced subtypes, like LinearGradient.
radius : int |
The radius used to draw rounded corners.
The default value is 10.
If radius is non-zero, the corners will be rounded, otherwise they will be sharp. The radius can also be specified separately for each corner by using the bottomLeftRadius, bottomRightRadius, topLeftRadius, and topRightRadius properties.
strokeColor : ShapePath |
The color used to draw the border of the rectangle.
When set to transparent
, no line is drawn.
The default value is red
.
See also QColor.
strokeStyle : ShapePath |
The style of the rectangle border.
Constant | Description |
---|---|
ShapePath.SolidLine | A solid line. This is the default value. |
ShapePath.DashLine | Dashes separated by a few pixels. The dashPattern property specifies the dash pattern. |
See also Qt::PenStyle.
strokeWidth : ShapePath |
The width of the border of the rectangle.
The default value is 4.
A width of 1 creates a thin line. For no line, use a negative value or a transparent color.
Note: The width of the rectangle's border does not affect the geometry of the rectangle itself or its position relative to other items if anchors are used.
The border is rendered within the rectangle's boundaries.
topLeftRadius : int |
The radius of the top left rectangle corner.
topRightRadius : int |
The radius of the top right rectangle corner.
Available under certain Qt licenses.
Find out more.