I'm trying to change the background in my QGraphicsView after it is initially created, but in QGraphicsView.drawBackground only part of the view is drawn. How do I trigger a repaint of the whole view (or certain parts of it)?
I'm trying to change the background in my QGraphicsView after it is initially created, but in QGraphicsView.drawBackground only part of the view is drawn. How do I trigger a repaint of the whole view (or certain parts of it)?
QWidget::update() will help you there. (Since QGraphicsView is a child of QWidget)
The coordinates are in "View Coordinates" which you might have to map from "Scene Coordinates" via QGraphicsView::mapFromScene()
I tried update() on the whole view I think, but still only part of the view was scheduled for background drawing. I'm not at work, so I don't have the actual program in front of me, but I'm pretty sure I tried what you're proposing. Are you sure this should work?
Well, it should, unless graphicsview is optimizing a bit (more than you would like)...and it seems to be (i.e. caching). But one look at the documentation revealed the nice solution to your problem: QGraphicsView::resetCachedContent()
I did try resetCachedContent(), but it did nothing really. Besides, caching is turned off by default according to Assistant.
My GV is created in a UI file and then as part of my program's init i set a brackground. This is the code I use:
Qt Code:
scene->setSceneRect(0, 0, fieldWidth, fieldHeight); fieldGV->setScene(scene);To copy to clipboard, switch view to plain text mode
Hope it helps.
mAx
do the image width and height and Scene rect width/height match ??
might be thers some scaling problem ???
Okay, but why can't you use setBackGroundBrush() again? I can call that from anywhere in my app and the background changes just fine. I guess it depends on exactly what you are trying to draw as the background.
mAx
workaround.
just add one item to scene and remove, this will redraw the background.
Rajesh Kumar Singh
Bangalore, India.
Qt Search
Must Watch:
See how we can connect digital world objects to our day to day life….
Or define the scene rect, no workaround needed. ;-)
Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
Nokia Software Manager, Qt Development
is it a partial background refresh where it just refreshes the scene and leaves everything outside the scene the old background color or does it just plain not work?
You might also try updating to 4.2.3 since it looks like they did something on this...
"General improvements
--------------------
- Graphics View
* Calling QGraphicsScene::update() without arguments now correctly
updates the entire scene.
* Changing the background brush in QGraphicsScene now correctly updates
the entire scene
"
Last edited by giverson; 9th March 2007 at 15:07.
Bookmarks