PDA

View Full Version : Faulty image when redering from a Painter device



dasheep
24th May 2012, 09:47
Hi Folks,

I use the following code to save a selection of a scene into a file (Qt 4.7.4):


if (mpScene->selectedItems().isEmpty()) return;
QList<QGraphicsItem*> items(mpScene->selectedItems());
QRect sourceRect;
boostForeach(QGraphicsItem* item, items) {
sourceRect = sourceRect.united(item->sceneBoundingRect().toRect());
}
QImage img(sourceRect.size(),QImage::Format_ARGB32_Premul tiplied);
QPainter p(&img);
mpView->scene()->clearSelection();
mpView->scene()->render(&p, QRectF(), sourceRect);
p.end();
QString path = QFileDialog::getSaveFileName(0,tr("Choose Image-File Destination"));
img.save(path,"JPG",100);

While the code works fine, the result is not satisfactory at all.
The following image is what I get:

7744


It seems like the renderer stops it's work in the middle or some cache is not written.
This does not happen with bigger scenes but selections rectangles are almost always corrupted
Has anybody any idea where this might come from ?

norobro
25th May 2012, 02:19
Heed the warning here (http://doc-snapshot.qt-project.org/4.8/qimage.html#QImage-2).