durbrak
27th December 2007, 12:08
Hey there,
I have a rather simple question. I have a QGraphicsView where I want to paint custom things on the background (which don't change size when the view is scaled).
For testing purposes I started testing with painting "Test" in drawBackground:
void View::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->save();
painter->setWorldMatrixEnabled(false);
painter->drawText(this->rect().center(), "Test");
painter->restore();
}To see that the scaling actually works, I've added a QGraphicsTextItem.
Now what happens, is that when I move the graphicsView and my previously painted "Test" goes outside the viewport and then goes back in, it's gone (or partially gone, if I only partially moved it outside the viewport).
QGraphicsView::setCacheMode(CacheNone) is set and I also tried playing around with optimization flags but nothing seemed to work.
Can you guys give me a hint on what's going wrong? I need to use custom painting, because there's going to be a world map painted and stuff...
Here are some screenshots for better understanding what my problem is:
http://img186.imageshack.us/img186/974/gv1bx3.jpg http://img401.imageshack.us/img401/8264/gv2eq0.jpg http://img183.imageshack.us/img183/1036/gv3tw5.jpg http://img401.imageshack.us/img401/1535/gv4jf0.jpg
I have a rather simple question. I have a QGraphicsView where I want to paint custom things on the background (which don't change size when the view is scaled).
For testing purposes I started testing with painting "Test" in drawBackground:
void View::drawBackground(QPainter *painter, const QRectF &rect)
{
painter->save();
painter->setWorldMatrixEnabled(false);
painter->drawText(this->rect().center(), "Test");
painter->restore();
}To see that the scaling actually works, I've added a QGraphicsTextItem.
Now what happens, is that when I move the graphicsView and my previously painted "Test" goes outside the viewport and then goes back in, it's gone (or partially gone, if I only partially moved it outside the viewport).
QGraphicsView::setCacheMode(CacheNone) is set and I also tried playing around with optimization flags but nothing seemed to work.
Can you guys give me a hint on what's going wrong? I need to use custom painting, because there's going to be a world map painted and stuff...
Here are some screenshots for better understanding what my problem is:
http://img186.imageshack.us/img186/974/gv1bx3.jpg http://img401.imageshack.us/img401/8264/gv2eq0.jpg http://img183.imageshack.us/img183/1036/gv3tw5.jpg http://img401.imageshack.us/img401/1535/gv4jf0.jpg