Triangle QML Type

A triangle. More...

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

ShapePath

Properties

Detailed Description

The Triangle type can be used to draw triangles with different dimensions and shapes. The type is enclosed in an invisible Rectangle type. The size of the triangle is determined by the size of the bounding rectangle. The dimensions of the triangle can be changed to make it elongated or squat with space around it by using the leftMargin, topMargin, rightMargin, and bottomMargin properties. The margins are set between the triangle and the edges of the parent rectangle.

Each Triangle 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 triangle 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.

Example Usage

You can use the Triangle component in Qt Design Studio to create triangles in different shapes and colors.

The QML code looks as follows:

TriangleItem {
    id: triangle
    strokeColor: "gray"
    fillColor: "light gray"
}

TriangleItem {
    id: squatTriangle
    bottomMargin: 10
    topMargin: 30
    fillColor: "#d3d3d3"
    strokeColor: "#808080"
}

TriangleItem {
    id: elongatedTriangle
    leftMargin: 15
    rightMargin: 15
    fillColor: "#d3d3d3"
    strokeColor: "#808080"
}

TriangleItem {
    id: pear
    radius: 20
    fillColor: "light gray"
    bottomMargin: 10
    arcRadius: 20
    strokeColor: "#808080"
}

Property Documentation

arcRadius : real

The radius used to draw rounded corners.

The default value is 5.

If radius is non-zero, the corners will be rounded, otherwise they will be sharp.

This property can be used together with the radius property to determine the shape of the triangle.


bottomMargin : real

The top margin between the triangle and the bounding rectangle.

Setting the top and bottom margins makes the triangle shorter and moves it away from the edge.

See also topMargin, leftMargin, and rightMargin.


dashOffset : ShapePath

The starting point of the dash pattern for the triangle 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 triangle 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 triangle 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 triangle 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.


joinStyle : enumeration

The join style used to connect two triangle 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.


leftMargin : real

The left margin between the triangle and the bounding rectangle.

Setting the left and right margins makes the triangle thinner and moves it away from the edge.

See also rightMargin, topMargin, and bottomMargin.


radius : int

The radius used to draw rounded corners.

The default value is 5.

If radius is non-zero, the corners will be rounded, otherwise they will be sharp.

This property can be used together with the arcRadius property to determine the shape of the triangle.

See also arcRadius.


rightMargin : real

The left margin between the triangle and the bounding rectangle.

Setting the left and right margins makes the triangle thinner and moves it away from the edge.

See also leftMargin, topMargin, and bottomMargin.


strokeColor : ShapePath

The color used to draw the border of the triangle.

When set to transparent, no line is drawn.

The default value is red.

See also QColor.


strokeStyle : ShapePath

The style of the triangle border.

ConstantDescription
ShapePath.SolidLineA solid line. This is the default value.
ShapePath.DashLineDashes 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.


topMargin : real

The top margin between the triangle and the bounding rectangle.

Setting the top and bottom margins makes the triangle lower and moves it away from the edge.

See also bottomMargin, leftMargin, and rightMargin.


Available under certain Qt licenses.
Find out more.