C
Rectangle QML Type
Paints a filled rectangle with optionally rounded corners. More...
| Import Statement: | import QtQuick |
| Since: | Qt Quick Ultralite 1.0 |
| Inherits: | |
| Inherited By: | AlternateKeysListHighlight, KeyboardBackground, and SelectionListBackground |
Properties
- border
(since Qt Quick Ultralite 3.0)- border.color : color
(since Qt Quick Ultralite 3.0) - border.width : int
(since Qt Quick Ultralite 3.0)
- border.color : color
- color : color
- gradient : Gradient
(since Qt Quick Ultralite 2.7) - radius : real
Detailed Description
Rectangle items are used to fill areas with solid color or gradients.
Appearance
Each Rectangle item is painted using a solid fill color, specified using the color property, or a gradient, defined using a Gradient type and set using the gradient property. If both a color and a gradient are specified, the gradient is used.
You can also create rounded rectangles using the radius property.
Example Usage
The following example shows a Rectangle item, which in this case is used to create a square with rounded corners.
import QtQuick 2.15 Rectangle { width: 100 height: 100 color: "red" radius: 10 }
See also Image.
Property Documentation
border group
border.color : color [since Qt Quick Ultralite 3.0]
border.width : int [since Qt Quick Ultralite 3.0]
The width and color used to draw the border of the rectangle.
The border is drawn inside the rectangle's bounds (width x height); it is never drawn outside them. The default border.color is black.
Note: Unlike Qt Quick, border.width defaults to 0 rather than 1, so no border is drawn until border.width is set explicitly. Setting only border.color has no visible effect.
Note: The border properties use their own on-demand storage, separate from the one shared by radius and gradient. A rectangle that does not set border.width or border.color in its QML only pays for one pointer. If it sets them, the storage is part of the rectangle. Reaching the border of such a rectangle from elsewhere, for example from another QML file or from C++, allocates the storage on first use.
Note: With a radius, the border is drawn underneath the fill. The border color shows through a semi-transparent fill color, and through any fill if the opacity of the rectangle is below 1.
Note: For the same reason, a fully transparent fill color does not produce a hollow outline when radius is set: the interior is filled with the border color, so the rectangle appears solid. Leave radius at 0 to draw a hollow frame.
Rectangle { width: 100 height: 100 color: "#41cd52" border.color: "black" border.width: 4 }
These properties were introduced in Qt Quick Ultralite 3.0.
See also color, radius, and gradient.
color : color
This property holds the color used to fill the rectangle.
The default color is white.

The following example shows rectangles with colors specified using hexadecimal and named color notation:
Rectangle { color: "#00B000" width: 80; height: 80 } Rectangle { color: "steelblue" y: 100; width: 80; height: 80 }
gradient : Gradient [since Qt Quick Ultralite 2.7]
The gradient to use to fill the rectangle.
This property allows for the construction of simple vertical or horizontal gradients.

Rectangle { y: 0; width: 80; height: 80 color: "lightsteelblue" } Rectangle { y: 100; width: 80; height: 80 gradient: Gradient { GradientStop { position: 0.0; color: "lightsteelblue" } GradientStop { position: 1.0; color: "blue" } } } Rectangle { y: 200; width: 80; height: 80 rotation: 90 gradient: Gradient { GradientStop { position: 0.0; color: "lightsteelblue" } GradientStop { position: 1.0; color: "blue" } } }
If both a gradient and a color are specified, the gradient will be used.
This property was introduced in Qt Quick Ultralite 2.7.
radius : real
This property holds the corner radius used to draw a rounded rectangle.
If radius is non-zero, the rectangle will be painted as a rounded rectangle, otherwise it will be painted as a normal rectangle. The same radius is used by all 4 corners; there is currently no way to specify different radii for different corners.
Available under certain Qt licenses.
Find out more.