On this page

QCImagePattern Class

QCImagePattern is a brush for painting image patterns. More...

Header: #include <QCImagePattern>
Inherits: QCBrush

Public Functions

QCImagePattern()
QCImagePattern(const QCImage &image)
QCImagePattern(const QCImage &image, const QRectF &rect, float angle = 0.0f, const QColor &tintColor = QColorConstants::White)
QCImagePattern(const QCImage &image, float x, float y, float width, float height, float angle = 0.0f, const QColor &tintColor = QColorConstants::White)
QCImagePattern(const QCImagePattern &pattern)
QCImagePattern(QCImagePattern &&other)
virtual ~QCImagePattern()
QCImage image() const
QSizeF imageSize() const
float rotation() const
void setImage(const QCImage &image)
void setImageSize(QSizeF size)
void setImageSize(float width, float height)
void setRotation(float rotation)
void setStartPosition(QPointF point)
void setStartPosition(float x, float y)
void setTintColor(const QColor &color)
QPointF startPosition() const
void swap(QCImagePattern &other)
QColor tintColor() const
QVariant operator QVariant() const
bool operator!=(const QCImagePattern &pattern) const
QCImagePattern &operator=(QCImagePattern &&other)
QCImagePattern &operator=(const QCImagePattern &pattern)
bool operator==(const QCImagePattern &pattern) const

Reimplemented Public Functions

virtual QCBrush::BrushType type() const override
QDataStream &operator<<(QDataStream &stream, const QCImagePattern &pattern)
QDataStream &operator>>(QDataStream &stream, QCImagePattern &pattern)

Detailed Description

QCImagePattern is a brush for painting image patterns. To use QCImage as a pattern, it should have some repeat flags turned on like QCPainter::ImageFlag::Repeat.

Here is a simple example:

// Setup 2 image patterns
static QImage image1(":/pattern2.png");
static QImage image2(":/pattern3.png");
auto flags = QCPainter::ImageFlag::Repeat |
             QCPainter::ImageFlag::GenerateMipmaps;
QCImage bg1 = painter.addImage(image1, flags);
QCImage bg2 = painter.addImage(image2, flags);
QCImagePattern ip1(bg1, 0, 0, 64, 64);
QCImagePattern ip2(bg2, 0, 0, 32, 32);
// Fill and stroke round rectangle with
// these image pattern brushes.
painter.beginPath();
painter.roundRect(50, 50, 180, 180, 40);
painter.setFillStyle(ip1);
painter.setStrokeStyle(ip2);
painter.fill();
painter.setLineWidth(20);
painter.stroke();

Note: When using image patterns, images are often scaled to smaller and it can be useful to set QCPainter::ImageFlag::GenerateMipmaps for the used QCImage to have smooth patterns.

Member Function Documentation

QCImagePattern::QCImagePattern()

Constructs a default image pattern. Image will not be set, please use setImage() after this constructor. Pattern start position position is (0, 0) and pattern size (100, 100). Pattern angle is 0.0 and tint color white (no tinting).

See also setImage().

QCImagePattern::QCImagePattern(const QCImage &image)

Constructs an image pattern. Pattern will use image. Please note that image should usually have at least QCPainter::ImageFlag::Repeat flag set. Pattern start position position is (0, 0) and pattern size (100, 100). Pattern angle is 0.0 and tint color white (no tinting).

QCImagePattern::QCImagePattern(const QCImage &image, const QRectF &rect, float angle = 0.0f, const QColor &tintColor = QColorConstants::White)

Constructs an image pattern. Pattern will use image. Please note that image should usually have at least QCPainter::ImageFlag::Repeat flag set. Pattern image position position and size is defined with rect. Pattern angle is angle and tint color is tintColor.

QCImagePattern::QCImagePattern(const QCImage &image, float x, float y, float width, float height, float angle = 0.0f, const QColor &tintColor = QColorConstants::White)

Constructs an image pattern. Pattern will use image. Please note that image should usually have at least QCPainter::ImageFlag::Repeat flag set. Pattern image start position position is ( x, y) and pattern size ( width, height). Pattern angle is angle and tint color is tintColor.

[noexcept] QCImagePattern::QCImagePattern(const QCImagePattern &pattern)

Constructs an image pattern that is a copy of the given pattern.

[constexpr noexcept] QCImagePattern::QCImagePattern(QCImagePattern &&other)

Move-constructs a new QCImagePattern from other.

[virtual noexcept] QCImagePattern::~QCImagePattern()

Destroys the image pattern.

QCImage QCImagePattern::image() const

Returns the image of the pattern.

See also setImage().

QSizeF QCImagePattern::imageSize() const

Returns the size of a single image in pattern.

See also setImageSize().

float QCImagePattern::rotation() const

Returns the pattern rotation in radians.

See also setRotation().

void QCImagePattern::setImage(const QCImage &image)

Sets the image of the pattern to image. Note: Image should usually have Repeat flag set when used in image pattern.

See also image().

void QCImagePattern::setImageSize(QSizeF size)

Sets the size of a single image in pattern to size.

See also imageSize().

void QCImagePattern::setImageSize(float width, float height)

Sets the size of a single image in pattern to ( width, height).

void QCImagePattern::setRotation(float rotation)

Sets the pattern rotation to rotation in radians. Rotation is done around the image startPosition(). The default value is 0.0, meaning the image is not rotated.

See also rotation().

void QCImagePattern::setStartPosition(QPointF point)

Sets the start point of image pattern to point. Start position means top-left corner of an image in pattern. Pattern will then be extended to all positions from here (if image Repeat flag has been set).

See also startPosition().

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

Sets the start point of image pattern to (x, y). Start position means top-left corner of an image in pattern. Pattern will then be extended to all positions from here (if image Repeat flag has been set).

void QCImagePattern::setTintColor(const QColor &color)

Sets the pattern tint color to color. The color of the pattern image will be multiplied with this tint color in the shader. The default value is white, meaning no tinting.

Note: To set alpha globally, use QCPainter::setGlobalAlpha()

See also tintColor().

QPointF QCImagePattern::startPosition() const

Returns the start point of image pattern.

See also setStartPosition().

[noexcept] void QCImagePattern::swap(QCImagePattern &other)

Swaps this pattern with other. This operation is very fast and never fails.

QColor QCImagePattern::tintColor() const

Returns the pattern tint color.

See also setTintColor().

[override virtual] QCBrush::BrushType QCImagePattern::type() const

Reimplements: QCBrush::type() const.

Returns the type of brush, QCBrush::BrushType::ImagePattern.

QVariant QCImagePattern::operator QVariant() const

Returns the image pattern as a QVariant.

bool QCImagePattern::operator!=(const QCImagePattern &pattern) const

Returns true if the image pattern is different from the given pattern; otherwise false.

See also operator==().

[noexcept] QCImagePattern &QCImagePattern::operator=(QCImagePattern &&other)

Move-assigns other to this QCImagePattern instance.

[noexcept] QCImagePattern &QCImagePattern::operator=(const QCImagePattern &pattern)

Assigns the given image pattern to this pattern and returns a reference to this image pattern.

bool QCImagePattern::operator==(const QCImagePattern &pattern) const

Returns true if the image pattern is equal to the given pattern; otherwise false.

See also operator!=().

Related Non-Members

QDataStream &operator<<(QDataStream &stream, const QCImagePattern &pattern)

Writes the given pattern to the given stream and returns a reference to the stream.

See also Serializing Qt Data Types.

QDataStream &operator>>(QDataStream &stream, QCImagePattern &pattern)

Reads the given pattern from the given stream and returns a reference to the stream.

See also Serializing Qt Data Types.

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