QPainter drawRect on QImage
-
Hi All:
I have a question about drawing rectangle on monochrom QImage.@
QImage _rowImg = QImage(QSize(10,10), QImage::Format_MonoLSB);
_rowImg.fill(Qt::color0); // fill _rowImg with Qt:color0
QPainter p;
p.begin(imgOutline);
// p.setCompositionMode(QPainter::RasterOp_SourceOrDestination);
p.setPen(QPen(Qt::color1)); // use 1 to draw, the pen with is 1 pixel solid line
p.drawRect(QRect(0,0,5,5));
p.end();@
// *********** END ************I suppose the result will be
1111100000
1000100000
1000100000
1000100000
1111100000
0000000000
0000000000
0000000000
0000000000However the result is
1111100000
1111100000
1111100000
1111100000
1111100000
0000000000
0000000000
0000000000
0000000000The default QBrush is 'NoBrush', My question is why the center of QRect(0,0,5,5) is filled with Qt:color1, which is not
supposed to. Do I miss anything here?Thanks!
-Todd
-
Hello tclin1998,
this works for me (Qt 4.7.2 and Windows):
@QImage _rowImg = QImage(QSize(10,10), QImage::Format_MonoLSB);
_rowImg.fill(Qt::color0); // fill _rowImg with Qt:color0
QPainter p;
p.begin(&_rowImg);
p.setPen(QPen(QColor(Qt::color0)));
p.setBrush(QBrush(QColor(Qt::color0), Qt::NoBrush));
p.drawRect(QRect(0,0,5,5));
p.drawRect(QRect(3,3,5,5));
p.end();
@But this seems a bit strange, why should color of pen be Qt::color0? And you need to set color of brush also to Wt::color0, even if you don't want any (Qt::NoBrush). However, drawing a second rectangle (as above) gives:
1111110000
1000010000
1000010000
1001111110
1001010010
1111110010
0001000010
0001000010
0001111110
0000000000Maybe there is an error in QImage and format Mono.
-
BTW
I'm using x86 Linux so it's using QImage::Format_MonoLSB should be correct.
If I can get the answer from this forum, is there a way to let the developer take a look this problem>Thanks
-Todd
-
Maybe someone from Nokia will read this thread.
You can also report it as bug in the "Qt bug tracker system":http://bugreports.qt.nokia.com/secure/Dashboard.jspaIn my opinion there should be no difference in using QImage::Format_Mono or QImage::Format_MonoLSB when accessing the image just through Qt classes. Only when you operate on the data directly it should be important.
-
This is from the 4.6.2 doc:
Warning: Painting on a QImage with the format QImage::Format_Indexed8 is not supported
I suppose QImage::mono is not supported either since it also uses table look up.-Todd