PDA

View Full Version : QPainter::drawImage randomly(?) omits some images



Al_
19th July 2014, 16:45
Hi

I need to print a series of small images (QR codes); 3 * 9 per page, total ~30 pages. The following code is called repeatedly.



QImage bbcode;
...
#ifdef QT_DEBUG
painter.setPen(Qt::darkRed);
painter.drawRect(textRect[Use4bbImage]);
bbcode.save(QString(QStringLiteral("%1_%2.jpg")).arg(printQuery.value(0).toInt()).arg(printQuery .value(1).toInt()), 0, 100);
qDebug() << "draw image" << bbcode << bbcode.rect() << "on" << textRect[Use4bbImage];
#endif
painter.drawImage(textRect[Use4bbImage], bbcode, bbcode.rect());

The debug output:

draw image QImage(QSize(140, 140) ) QRect(0,0 140x140) on QRect(0,0 2000x2000)
Strangely, only appproximately half of the images are printed (on some pages almost all, on others only a few). The code above confirms that all three parameters to painter.drawImage are correct: the textRect[Use4bbImage] is the correct QRect (as the darkRed frame is drawn around the place where the image should be placed), the image bbcode exists (as it is correctly saved to a file), bbcode.rect() is always the same size (as per debug output).

I use Qt 5.3.1 on linux (Ubuntu 12.04 LTS). The issue remains whether I print to pdf or whether I print to a real printer.

Any ideas? How should I proceed to find the bug?

Al_

Al_
20th July 2014, 09:14
Ok, I found a work-around.

The images are QR codes that are for some reason stored as RGB images (but of course in reality only black and white is used). If I convert the images to monochrome prior to printing, then all are printed.

I assume that the color-coded (but only b/w) images exceed some complexity limit of Qt. I would still be interested what the exact limitation is.

Al_