PDA

View Full Version : GraphicsView update background



maverick_pol
27th February 2008, 12:39
Hi,

I have already enabled updates for the graphicsView, set cacheBackground as the mode for updating the gview. I need to change the background color. WHen I set the colour and invoke update/repaint for the view or viewport nothing happens. When I invoke "fitInView(..sceneRect)" the background is repainted.
How to update the background using update/repaint/etc ?
My view settings:


...
m_view->setCacheMode(QGraphicsView::CacheBackground);
m_view->setOptimizationFlag(QGraphicsView::DontClipPainter );
m_view->setOptimizationFlag(QGraphicsView::DontSavePainter State);
m_view->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);
m_view->setRenderHints( QPainter::HighQualityAntialiasing);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
....


While initializing the view I can set view->setBackgroundColor(Qt::blue),etc. And it works fine. But how to update the backgroundcolor later?

Thanks.

wysota
27th February 2008, 12:44
How about using QGraphicsScene::setBackgroundBrush()?

maverick_pol
27th February 2008, 12:47
setBackgroundBrush overides scene's background. I have a custom background in the scene and do not want to change this. Scene rect is smaller than the view size, and to hide that I need to set the same colour for the view and for the scene.

wysota
27th February 2008, 12:49
In that case try changing the QPalette::Base component of the view's palette.

maverick_pol
27th February 2008, 12:54
This do not work:


QPalette palette;
palette.setBrush(QPalette::Base,m_colorMap.value("NODTA"));//NODTA-> is my color index
m_view->setPalette(palette);
m_view->repaint(true);


Still using fitInview -> changes the background. Maybe you have and idea what is invoked in the fitInView? (I know the view is transformed /scaled)

Kacper

maverick_pol
27th February 2008, 13:03
Ok,

I might have found the problem. While changing the background, the view(if the cachBackground is enabled) repainted the background from the cache. When I turned off the cachBackground the repainting works. yet, I can't turn off the background cache, because repainting works 10x slower.

I can reset the cache, but it works slower. Howto update the view background without clearing the cache?(when the cache is enabled) ?

Kacper

wysota
27th February 2008, 13:34
Maybe you should manualy call update()?

maverick_pol
27th February 2008, 14:50
I tried that already. Nothing happens.

wysota
27th February 2008, 14:54
Don't you think that every update causes the background cache to be regenerated? If so, you can turn off the cache, redraw the background and then turn the cache back on.

pherthyl
27th February 2008, 19:25
Well if you are changing something in the background then naturally you need to reset the cache. As you seem to have discovered, QGraphicsView::resetCachedContent () is the key to that.
Of course the following repaint will be slower because it needs to regenerate the cache. You can't get away from that.