On this page

QCLinearGradient Class

QCLinearGradient is a brush for linear gradient painting. More...

Header: #include <QCLinearGradient>
Inherits: QCGradient

Public Functions

QCLinearGradient()
QCLinearGradient(QPointF start, QPointF end)
QCLinearGradient(float startX, float startY, float endX, float endY)
QPointF endPosition() const
void setEndPosition(QPointF end)
void setEndPosition(float x, float y)
void setStartPosition(QPointF start)
void setStartPosition(float x, float y)
QPointF startPosition() const

Detailed Description

Liner gradient interpolate colors between start and end points along a linear pattern, so horizontally, vertically or diagonally. The gradient starts from startPosition() and ends to endPosition(). Outside this area, the colors are the starting and the ending color.

Here is a simple example:

QRectF rect1(50, 50, 200, 200);
QCLinearGradient lg(rect1.topLeft(),
                    rect1.bottomRight());
lg.setColorAt(0.0, "#1a2a6c");
lg.setColorAt(0.5, "#b21f1f");
lg.setColorAt(1.0, "#fdbb2d");
painter.setFillStyle(lg);
painter.fillRect(rect1);

Member Function Documentation

QCLinearGradient::QCLinearGradient()

Constructs a default linear gradient. Gradient start color position is (0, 0) and end color position (0, 100). Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QCLinearGradient::QCLinearGradient(QPointF start, QPointF end)

Constructs a linear gradient. Gradient start color position is start and end color position end. Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QCLinearGradient::QCLinearGradient(float startX, float startY, float endX, float endY)

Constructs a linear gradient. Gradient start color position is (startX, startY) and end color position (endX, endY). Gradient start color is white (255, 255, 255) and end color transparent black (0, 0, 0, 0).

QPointF QCLinearGradient::endPosition() const

Returns the end point of linear gradient.

See also setEndPosition().

void QCLinearGradient::setEndPosition(QPointF end)

Sets the end point of linear gradient to end.

See also endPosition().

void QCLinearGradient::setEndPosition(float x, float y)

Sets the end point of linear gradient to ( x, y).

void QCLinearGradient::setStartPosition(QPointF start)

Sets the start point of linear gradient to start.

See also startPosition().

void QCLinearGradient::setStartPosition(float x, float y)

Sets the start point of linear gradient to ( x, y).

QPointF QCLinearGradient::startPosition() const

Returns the start point of linear gradient.

See also setStartPosition().

© 2025 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.