fpbosman
10th May 2011, 10: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.fillRect(rect,QBrush(Qt::red));
painter.setBrush( brushBitmap );
painter.drawRect(rect1);
painter.setBrush(QBrush(Qt::black, Qt::BDiagPattern));
painter.drawRect(rect2);
The png:
6395
Result:
6393
Expected Result:
6394
I believe its the same problem like this unresolved thread http://www.qtcentre.org/threads/35803-QGraphicsItem-filling-with-pattern
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.fillRect(rect,QBrush(Qt::red));
painter.setBrush( brushBitmap );
painter.drawRect(rect1);
painter.setBrush(QBrush(Qt::black, Qt::BDiagPattern));
painter.drawRect(rect2);
The png:
6395
Result:
6393
Expected Result:
6394
I believe its the same problem like this unresolved thread http://www.qtcentre.org/threads/35803-QGraphicsItem-filling-with-pattern