QCanvasImagePattern Class | Qt Canvas Painter | Qt 6.12.0
Description: QCanvasImagePattern is a brush for painting image patterns.
Keywords: class

- Qt 6.12
- Qt Canvas Painter
- C++ Classes
- QCanvasImagePattern
- Qt Canvas Painter | Commercial or GPLv3

# QCanvasImagePattern Class

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

Header: | `#include <QCanvasImagePattern>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)` `target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)`
Since: | Qt 6.11

- List of all members, including inherited members

## Public Functions

| QCanvasImagePattern(const QCanvasImage &image)
| QCanvasImagePattern(const QCanvasImage &image, const QRectF &rect, float angle = 0.0f, const QColor &tintColor = QColorConstants::White)
| QCanvasImagePattern(const QCanvasImage &image, float x, float y, float width, float height, float angle = 0.0f, const QColor &tintColor = QColorConstants::White)
| QCanvasImagePattern(const QCanvasImagePattern &)
| QCanvasImagePattern(QCanvasImagePattern &&)
QCanvasImage | image() const
QSizeF | imageSize() const
float | rotation() const
void | setImage(const QCanvasImage &image)
void | setImageSize(float width, float height)
void | setImageSize(QSizeF size)
void | setRotation(float rotation)
void | setStartPosition(float x, float y)
void | setStartPosition(QPointF point)
void | setTintColor(const QColor &color)
QPointF | startPosition() const
QColor | tintColor() const
| operator QVariant() const

## Related Non-Members

bool | operator!=(const QCanvasImagePattern &lhs, const QCanvasImagePattern &rhs)
QDataStream & | operator<<(QDataStream &stream, const QCanvasImagePattern &pattern)
bool | operator==(const QCanvasImagePattern &lhs, const QCanvasImagePattern &rhs)
QDataStream & | operator>>(QDataStream &stream, QCanvasImagePattern &pattern)

## Detailed Description

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

Here is a simple example:

     // Setup 2 image patterns
     static QImage image1(":/pattern2.png");
     static QImage image2(":/pattern3.png");
     auto flags = QCanvasPainter::ImageFlag::Repeat |
                  QCanvasPainter::ImageFlag::GenerateMipmaps;
     QCanvasImage bg1 = painter.addImage(image1, flags);
     QCanvasImage bg2 = painter.addImage(image2, flags);
     QCanvasImagePattern ip1(bg1, 0, 0, 64, 64);
     QCanvasImagePattern 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 QCanvasPainter::ImageFlag::GenerateMipmaps for the used QCanvasImage to have smooth patterns.

## Member Function Documentation

### QCanvasImagePattern::QCanvasImagePattern(const QCanvasImage &image)

Constructs an image pattern. Pattern will use image. Please note that image should usually have at least QCanvasPainter::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).

### QCanvasImagePattern::QCanvasImagePattern(const QCanvasImage &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 QCanvasPainter::ImageFlag::Repeat flag set. Pattern image position position and size is defined with rect. Pattern angle is angle and tint color is tintColor.

### QCanvasImagePattern::QCanvasImagePattern(const QCanvasImage &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 QCanvasPainter::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.

### QCanvasImagePattern::QCanvasImagePattern(const QCanvasImagePattern &)

Destroys the image pattern.

### `[constexpr noexcept default]` QCanvasImagePattern::QCanvasImagePattern(QCanvasImagePattern &&)

Move-constructs an instance of QCanvasImagePattern.

### QCanvasImage QCanvasImagePattern::image() const

Returns the image of the pattern.

See also setImage().

### QSizeF QCanvasImagePattern::imageSize() const

Returns the size of a single image in pattern.

See also setImageSize().

### float QCanvasImagePattern::rotation() const

Returns the pattern rotation in radians.

See also setRotation().

### void QCanvasImagePattern::setImage(const QCanvasImage &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 QCanvasImagePattern::setImageSize(float width, float height)

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

See also imageSize().

### void QCanvasImagePattern::setImageSize(QSizeF size)

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

This is an overloaded function.

### void QCanvasImagePattern::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 QCanvasImagePattern::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).

See also startPosition().

### void QCanvasImagePattern::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).

This is an overloaded function.

### void QCanvasImagePattern::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 QCanvasPainter::setGlobalAlpha()

See also tintColor().

### QPointF QCanvasImagePattern::startPosition() const

Returns the start point of image pattern.

See also setStartPosition().

### QColor QCanvasImagePattern::tintColor() const

Returns the pattern tint color.

See also setTintColor().

### QCanvasImagePattern::operator QVariant() const

Returns the image pattern as a QVariant.

## Related Non-Members

### `[noexcept]` bool operator!=(const QCanvasImagePattern &lhs, const QCanvasImagePattern &rhs)

Returns `true` if the image pattern lhs is different from rhs; `false` otherwise.

See also operator==().

### QDataStream &operator<<(QDataStream &stream, const QCanvasImagePattern &pattern)

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

See also Serializing Qt Data Types.

### `[noexcept]` bool operator==(const QCanvasImagePattern &lhs, const QCanvasImagePattern &rhs)

Returns `true` if the image pattern lhs is equal to rhs; `false` otherwise.

See also operator!=().

### QDataStream &operator>>(QDataStream &stream, QCanvasImagePattern &pattern)

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

See also Serializing Qt Data Types.