[Interest] double-buffering, quality drop

Alexander Semke Alexander.Semke at web.de
Tue Feb 3 08:55:13 CET 2015


Hi,

I'm one of the developers of LabPlot, a KDE-application for interactive 
plotting and analysis of data. I'm struggling with a problem since long time 
that prevents the next release of the software. So, any help on this issue 
will be highly appreciated :-)

To speed up the painting of large curves we use the "double buffering" 
technique - the curve is painted on a QPixmap in updatePixmap()-function (only 
called when the user changes the properties of the curve) and then painted to 
Curve (derived from QGraphicsItem) in the paint()-function (called much more 
frequently)

Curve::updatePixmap() {
	QPixmap pixmap(boundingRectangle.width(), boundingRectangle.height());
	QPainter painter(&pixmap);
	painter.setRenderHint(QPainter::Antialiasing, true);
	//perform drawing

	m_pixmap = pixmap;
}

Curve::paint((QPainter* painter, const QStyleOptionGraphicsItem*, QWidget*) {
	painter->save();
	painter->setPen(Qt::NoPen);
	painter->setBrush(Qt::NoBrush);
	painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
	painter->drawPixmap(boundingRectangle.topLeft(), m_pixmap);
	painter->restore();
}

The performance gain is huge. But there is also a huge drop in the quality 
that I cannot explain. I attached two screenshots - with and without double 
buffering. Without double buffering just means that all the drawing stuff is 
done in paint() directly. 

What am I doing here wrong? Any ideas?


-- 
Alexander
-------------- next part --------------
A non-text attachment was scrubbed...
Name: with_double_buffer.jpg
Type: image/jpeg
Size: 51751 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150203/2cbeae7e/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: without_double_buffer.jpg
Type: image/jpeg
Size: 49964 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150203/2cbeae7e/attachment-0001.jpg>


More information about the Interest mailing list