PDA

View Full Version : Bug in QGraphicsScene?



tbcpp
11th June 2009, 22:56
Okay, so I have a dialog widget inside a QGraphicsView, I want a custom background for the view, so I subclassed QGraphicsScene and overloaded the drawBackground() function. All works as expected. However, when I change the QGraphicsView to use OpenGL, the rectangle handed into the drawBackground function covers the entire view.

Let me give the code first of all:



void SceneHandler::drawBackground(QPainter *painter, const QRectF & rect) {

QRect source (xoffset, yoffset, rect.width(), rect.height());
painter->drawImage(rect, img, source);

QStringList qsl;
qsl << QString::number(rect.x());
qsl << QString::number(rect.y());
qsl << QString::number(rect.width());
qsl << QString::number(rect.height());
qDebug(qsl.join(",").toAscii());
}


When using the system (default) rasteriser this gives me:


161,263,682,461
333,299,462,24
333,299,462,24
333,301,12,21
333,299,462,24
333,301,12,21
333,301,12,21
333,301,12,21


when using OpenGL I get


95,176,682,461
95,176,682,461
95,176,682,461
95,176,682,461
95,176,682,461
95,176,682,461
95,176,682,461
95,176,682,461


This causes a whole ton of artifacts, because the background painter is overwriting the entire viewport. Then only the changed widgets are redrawn. You can see this by the fact that when we use the system rasteriser we get widths of 12 as parts of widgets are redrawn. With opengl the width is is always 682.

Any ideas why this is happening?

Amargedon
12th June 2009, 07:10
As far as I knows it is not possible to update parts of the view when using OpenGL. It is possible if you don't use OpenGL, and that is wat you experienced also.

tbcpp
12th June 2009, 14:23
Thanks for the help. I fixed the bug in my code. For the record you must include this at the end of the drawBackground() function



invalidate(rect, QGraphicsScene::ItemLayer | QGraphicsScene::ForegroundLayer);


This will insure that the upper layers are invalidated for the same rectangle as the background. It seems odd that Qt doesn't do this by default...