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);
qsl <<
QString::number(rect.
width());
qsl <<
QString::number(rect.
height());
qDebug(qsl.join(",").toAscii());
}
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());
}
To copy to clipboard, switch view to plain text mode
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
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
To copy to clipboard, switch view to plain text mode
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
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
To copy to clipboard, switch view to plain text mode
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?
Bookmarks