View Full Version : TexturePattern backgroundcolour problem

10th May 2011, 11:22
When I use a bitmap as a texture pattern, the background is not correctly displayed. When you use a build-in pattern, this is done correctly.

The main question to solve is: Fill a figure(rectangle, cirlce, etc...) with a bitmap texturePattern and displaying the painters background and foreground colors correctly.

I want to know if it's a bug in QT 4.7 ? or I need to set another parameter (besides the QPainter::setBackgroundMode() ) to have the correct behavour?

A workaround to this problem would be the draw 2 times the figure, first with a solidfilled brush and second with a brush with the bitmap pattern fill.
BUT I prefer NOT to use this option.

Here is some code to reproduce the problem:

QBitmap bitmap("debug/test.png");
QBrush brushBitmap(bitmap);
QRect rect(80,0,160,100);
QRect rect1(0,10,150,510);
QRect rect2(160,10,150,510);

painter.setBackgroundMode( Qt::OpaqueMode ); // Qt::OpaqueMode / Qt::TransparentMode
painter.setBackground(QColor(0,255,0)); // Background set to green
painter.setPen(QPen(Qt::black, 1, Qt::SolidLine));


painter.setBrush( brushBitmap );

painter.setBrush(QBrush(Qt::black, Qt::BDiagPattern));

The png:


Expected Result:

I believe its the same problem like this unresolved thread http://www.qtcentre.org/threads/35803-QGraphicsItem-filling-with-pattern

11th May 2011, 11:09
Try setting different composition modes, see if it helps.

11th May 2011, 16:14
No, unfortunately it didn't help.

I strongly believe it's a bug in QT.

I think the bug is located in the $QTDIR\src\gui\painting\qemulationpaintengine.cpp: 83

if (style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern)
real_engine->fill(path, s->bgBrush);
should be

if ((style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern) || (style == Qt::TexturePattern ))
real_engine->fill(path, s->bgBrush);

I will post this bug to QT bugreport system, and will wait for an answer there.