QPixmap-当大小大于源图像时如何重复像素图

问题描述

我正在调查有关Qpixmap如何正确设置图像像素图(https://doc.qt.io/qt-5/qpixmap.html#scaled等)的Qt文档。

我正在尝试将各种像素图设置为QGraphicItem,但似乎都不自然:

enter image description here

使用以下代码行(及其参数变体),但我无法获得想要的结果:

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

有什么方法可以设置像素图,以便在保持宽高比的对象上“重复”它,从而使它看起来像这样的项目?

谢谢您的帮助。

解决方法

这是基于G.M.评论:

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

它恰好满足了我的需求:

result