GraphicsView update background
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:
Code:
...
m_view
->setOptimizationFlag
(QGraphicsView::DontSavePainterState);
m_view
->setViewportUpdateMode
(QGraphicsView::FullViewportUpdate);
m_view
->setRenderHints
( QPainter::HighQualityAntialiasing);
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
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.
Re: GraphicsView update background
Re: GraphicsView update background
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.
Re: GraphicsView update background
In that case try changing the QPalette::Base component of the view's palette.
Re: GraphicsView update background
This do not work:
Code:
palette.
setBrush(QPalette::Base,m_colorMap.
value("NODTA"));
//NODTA-> is my color indexm_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
Re: GraphicsView update background
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
Re: GraphicsView update background
Maybe you should manualy call update()?
Re: GraphicsView update background
I tried that already. Nothing happens.
Re: GraphicsView update background
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.
Re: GraphicsView update background
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.