[GraphicsView] drawBackground junks around
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:
Code:
{
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
Re: [GraphicsView] drawBackground junks around
Why do you disable the matrix? It doesn't make much sense to do that...
Re: [GraphicsView] drawBackground junks around
Quote:
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'.
Re: [GraphicsView] drawBackground junks around
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).
Re: [GraphicsView] drawBackground junks around
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...
Re: [GraphicsView] drawBackground junks around
Quote:
Originally Posted by
durbrak
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?
Quote:
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.
Quote:
Reimplementing QGraphicsView::paintEvent() somehow doesn't paint at all, lol...
Depends how you reimplement it.