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?
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?