不平铺的 QBrush 纹理
使用带有纹理的 QBrush 时,是否有一种简单的方法可以消除平铺?
QImage* texture = CreateQImage(); // create texture
QBrush* brush = new QBrush(*texture); // create texture brush
QPainter* painter = CreateQPainter(); // create painter
painter->fillRectangle(0, 0, 500, 500, *brush);
假设我们有一个大小为 20x20 像素的 QImage 纹理。上面的代码将在整个填充的矩形上平铺该纹理。有没有一种简单的方法可以只绘制该纹理的单个实例? QBrush 的使用至关重要。
理论上,我可以重新加载以 QBrush 作为输入的 QPainter 的每个填充和绘制方法,并使用
QPainter.drawImage()method, but I think there must be a simplier way.
谢谢,托尼。
Is there an easy way to get rid of tiling when using a QBrush with texture?
QImage* texture = CreateQImage(); // create texture
QBrush* brush = new QBrush(*texture); // create texture brush
QPainter* painter = CreateQPainter(); // create painter
painter->fillRectangle(0, 0, 500, 500, *brush);
Suppose we have a QImage texture with size of 20x20 pixels. The code above will tile this texture all across the rectangle being filled. Is there an easy way to draw only a single instance of this texture? The QBrush usage is crucial.
Theoretically, I could reload every fill and draw method of the QPainter that takes a QBrush as input and use a
QPainter.drawImage()
method, but I think there must be a simplier way.
Thanks, Tony.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为没有(参见 Qt::BrushStyle - 唯一带有纹理的样式),而且在我看来,它并没有真正意义。如果您只想要一张图像,请按照您的说明使用
drawImage
函数。(不平铺的问题之一是:用什么填充矩形的其余部分?什么都没有?一些默认背景颜色?其他一些
QBrush
属性?)I don't think there is (see Qt::BrushStyle - the only style with a texture tiles it), and it wouldn't really make sens IMO. If you just want one image, use the
drawImage
functions as you've stated.(One of the problems with not tiling is: what do you fill the rest of the rectangle with? Nothing? Some default background color? Some other
QBrush
attribute?)