PDA

View Full Version : Scrolling problem with background using View/Scene



nileshsince1980
17th October 2007, 10:25
Hi,
I am using view/Scene architecture to show rectangels and lines with background picture.
I have drawn background in GraphicsScene::drawBackground(..) function.
To speed up rendering I have set cache background

view->setCacheMode(QGraphicsView::CacheBackground);
But using this when I zoom and then scroll the content there is artifacts comes. After scrolling scene doesnt refresh property.Background image doesnt refresh.

I have tried using

GraphicsView::scrollContentsBy(int dx, int dy)
{
scene()->invalidate(sceneRect(), QGraphicsScene::BackgroundLayer);
QGraphicsView::scrollContentsBy(dx, dy);
}
But this also doesnt refersh the screen.
I want to refresh only portion which is visible because of scrolling.
Can anybody have solution for this.

wysota
20th October 2007, 23:02
How did you implement drawBackground()? What happens if you disable the cache?

nileshsince1980
22nd October 2007, 06:00
I have drawn background using svg render class.
If I disable the cache, and select the rectangle & move them, it becomes very slow.
So i m tring to use cache background. But with cache background it doesnt refershe the screen after zooming and then scrolling.
I want to refersh the portion of screen which is visible due to scrolling after zooming the screen.

wysota
22nd October 2007, 06:11
So without caching the background the output is correct? From what I understand the caching will cause a degrade in quality while zooming, because it converts the vector-based svg to a bitmap based pixmap. But I don't know if that's the effect you are experiencing.

nileshsince1980
22nd October 2007, 06:53
Without cache background output is correct but it slows down rendering,Also if we select rects and move them it also slows down.
Can you tell me which is faster svg rendering Or bitmap ?

wysota
22nd October 2007, 08:19
bitmap is definitely faster. I suggest you do your own caching - render the svg to a pixmap after each zoom using the needed pixmap size and then just draw the pixmap from within drawBackground(). Just make sure you invalidate and rerender the pixmap after each change to the zoom level. An alternative is to get rid of svg and just render to pixmap once and then use it as a background brush for your scene.