QPixmap - How to repeat pixmap, when size is bigger than source image

Viewed 207

I was investigating Qt docs regarding QPixmap how to set image pixmap properly (https://doc.qt.io/qt-5/qpixmap.html#scaled, etc.).

I was experimenting with different kinds of setting pixmap to a QGraphicItem but none of them seemed natural:

enter image description here

Using the following line of code (and its parameters variations), but I was not able to get results I want:

this->mPixmap = QPixmap(path).scaled(mRect.width(), mRect.height(), Qt::KeepAspectRatioByExpanding);

Is there any way I can set pixmap so it would be "repeated" on the object with kept aspect ratio, so it would look n the item like this?

Thank you for any kind of help.

1 Answers

Here is a solution, based on G.M. commentary:

painter->setBrush(QPixmap(":/img/conv.png").scaledToHeight(mRect.height()));
painter->setBrushOrigin(mRect.topLeft().x(), mRect.topLeft().y());
painter->drawRect(mRect);

And it does exactly what I needed:

result

Related