RectangleItem QML Type

A filled rectangle with an optional border. More...

Import Statement: import QtQuick.Studio.Components
Since: QtQuick.Studio.Components 1.0
Inherits:

Shape

Properties

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. Additionally, bevel can be applied on any corner to cut it off sharply.

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: rectangle1
    x: 480
    y: 164
    width: 409
    height: 307
    radius: 0
    gradient: RadialGradient {
        GradientStop {
            position: 0
            color: "#cea1f9fc"
        }

        GradientStop {
            position: 1
            color: "#ec7d7d"
        }
        focalY: rectangle1.height * 0.5
        focalX: rectangle1.width * 0.5
        focalRadius: Math.min(rectangle1.width, rectangle1.height) * 0
        centerY: rectangle1.height * 0.5
        centerX: rectangle1.width * 0.5
        centerRadius: Math.min(rectangle1.width, rectangle1.height) * 0.5
    }
    strokeWidth: 6
    strokeColor: "#ff0000"
    bottomLeftRadius: 30
    topRightRadius: 30
    adjustBorderRadius: true
}

RectangleItem {
    id: rectangle2
    x: 954
    y: 164
    width: 409
    height: 307
    radius: 0
    fillColor: "#c062606a"
    strokeWidth: -1
    topRightRadius: 30
    strokeColor: "#8b8a8a"
    bottomLeftRadius: 30
    adjustBorderRadius: true
}

RectangleItem {
    id: rectangle3
    x: 480
    y: 533
    width: 409
    height: 307
    radius: 0
    gradient: LinearGradient {
        y2: rectangle3.height * 1
        y1: rectangle3.height * 0
        x2: rectangle3.width * 1
        x1: rectangle3.width * 0
        GradientStop {
            position: 0.10526
            color: "#e77979"
        }
        GradientStop {
            position: 0.67105
            color: "#716767"
        }
    }
    topRightBevel: true
    topRightRadius: 30
    strokeWidth: 6
    strokeColor: "#ff0000"
    bottomLeftRadius: 0
    adjustBorderRadius: true
}

RectangleItem {
    id: rectangle4
    x: 954
    y: 533
    width: 409
    height: 307
    radius: 30
    fillColor: "#d87c7c"
    borderMode: 2
    dashOffset: 3
    joinStyle: 2
    strokeStyle: 5
    topRightBevel: false
    strokeWidth: 6
    strokeColor: "#ff0000"
    adjustBorderRadius: true
}

Property Documentation

adjustBorderRadius : bool

It defines how the border radius is calculated for the corners.


bevel : bool

Whether the rectangle corner is beveled.


borderMode : int

It defines where the border is drawn.

ConstantDescription
Border.InsideThe border is drawn along the inside edge of the item and does not affect the item width. This is the default value.
Border.MiddleThe border is drawn over the edge of the item and does not affect the item width.
Border.OutsideThe border is drawn along the outside edge of the item and increases the item width by the value of strokeWidth.

The default value is 0, which sets the border along the inside edge of the Item.

See also strokeWidth.


bottomLeftBevel : bool

The bevel of the bottom left rectangle corner.

See also bevel.


bottomLeftRadius : int

The radius of the bottom left rectangle corner.


bottomRightBevel : bool

The bevel of the bottom right rectangle corner.

See also bevel.


bottomRightRadius : int

The radius of the bottom right rectangle corner.


capStyle : int

The cap style defines how the end points of lines are drawn using QPainter. The cap style only applies to lines with width 1 or greater. The cap style can be square, flat, or round.

The default is Qt::SquareCap

See also QPen::capStyle().


dashOffset : alias

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 : alias

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.

Each dash is also subject to cap styles, and therefore a dash of 1 with square cap set will extend 0.5 pixels out in each direction resulting in a total width of 2.

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 : alias

The rectangle fill color.

A rectangle can be filled with a solid color or with any of the linear, radial, or conical gradients.

When set to transparent, no filling occurs.

The default value is white.


gradient : ShapeGradient

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.


joinStyle : int

The join style is used to connect two border line segments.

ConstantDescription
ShapePath.MiterJoinThe outer edges of the lines are extended to meet at an angle, and this area is filled.
ShapePath.BevelJoinThe triangular notch between the two lines is filled. This is the default value.
ShapePath.RoundJoinA circular arc between the two lines is filled.

See also Qt::PenJoinStyle.


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.

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 : alias

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 : int

The style of the rectangle stroke.

When set to None, no stroke is drawn.

The stroke can be set to have a Solid, Dash, Dot, Dash Dot, or Dash Dot Dot pattern.

The default value is Solid.


strokeWidth : alias

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.


topLeftBevel : bool

The bevel of the top left rectangle corner.

See also bevel.


topLeftRadius : int

The radius of the top left rectangle corner.


topRightBevel : bool

The bevel of the top right rectangle corner.

See also bevel.


topRightRadius : int

The radius of the top right rectangle corner.


© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.