PDA

View Full Version : [GraphicsView] drawBackground junks around



durbrak
27th December 2007, 13: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

wysota
27th December 2007, 14:14
Why do you disable the matrix? It doesn't make much sense to do that...

durbrak
27th December 2007, 14:21
I have a QGraphicsView where I want to paint custom things on the background (which don't change size when the view is scaled).

I do that so the background doesn't get scaled when the view is scaled. It should be sort of 'static'.

wysota
27th December 2007, 15:47
If it is to be static to the view, then don't paint it in drawBackground which is meant to be static to the scene. Instead reimplement the paint event of the view and draw there (just remember to draw on the viewport and not the view itself).

durbrak
27th December 2007, 16:34
Well no, not static to the view. With "static" I just meant, that it shouldn't be scaled/transformed or whatsoever...

I just want to paint 256x256 png tiles of maps. But painting the whole world/europe in the complete scene background would result in a huge pixmap and that is not efficient. So I wanted to just paint the exposed area (the one that is actually visible).

Reimplementing QGraphicsView::paintEvent() somehow doesn't paint at all, lol...

wysota
27th December 2007, 16:53
Well no, not static to the view. With "static" I just meant, that it shouldn't be scaled/transformed or whatsoever...
That doesn't explain why you disabled the world matrix... And I think your assumption is wrong - if you zoom in, the map should zoom in as well, shouldn't it?


I just want to paint 256x256 png tiles of maps. But painting the whole world/europe in the complete scene background would result in a huge pixmap and that is not efficient.
Take a look at the parameters passed to drawBackground.


Reimplementing QGraphicsView::paintEvent() somehow doesn't paint at all, lol...
Depends how you reimplement it.