Hi. Generally what I want to achieve is that the drawn background image sticks to the "animated camera" (if you agree on calling the animation of QGraphicsView's sceneRect as animating a camera view).
A visualization of my problem:
Below you see, in this order, the first menu screen, the second menu screen, and the bad transition I get from the first to the second menu screen. It looks bad because in the transition the background is also moving, even though it really shouldn't. It seems that QT actually replicates/tiles the background image over the complete scene.
screen1.jpgscreen2.jpgscreentransition.jpg
Changing to set the backgroundBrush on the QGraphicsView rather than the QGraphicsScene did unfortunately not have any effect (problem remains the same).
Regarding caching:
In my QGraphicsview I use:
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setViewportUpdateMode(FullViewportUpdate);
setCacheMode(CacheBackground);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setViewportUpdateMode(FullViewportUpdate);
setCacheMode(CacheBackground);
setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
To copy to clipboard, switch view to plain text mode
Disabling the CacheBackground does not fix the problem either, but decreases performance significantly.
Regarding the items I place in the scene (i.e. the menu screens), I use
setCacheMode(QGraphicsItem::DeviceCoordinateCache)
To copy to clipboard, switch view to plain text mode
I'm quite reluctant to touch (override) the drawBackground(), basically because I've already tried before (when I was tinkering how to make sure the view always scales with my viewport, which I solved via fitInView(scene()->sceneRect(), Qt::IgnoreAspectRatio) at last). And I did not have much success in understanding what the parameters are, or, basically how to draw the background correctly.
Added after 28 minutes:
This (click me) got me close to the solution of my problem. However, the background image is not correctly scaled. My current solution to this scaling problem is that inside the drawBackground method, I replace the drawPixmap() call with
painter->drawPixmap(old.mapRect(rect), backgroundImage.scaled(viewport()->width(), viewport()->height()), old.mapRect(rect));
painter->drawPixmap(old.mapRect(rect), backgroundImage.scaled(viewport()->width(), viewport()->height()), old.mapRect(rect));
To copy to clipboard, switch view to plain text mode
While this works, I discovered that drawBackground() is called ca. 30 times during a transition from one screen to the next, and once I'm full screen (and at high resolution) this causes harsh performance drops. Why does QT have to redraw the background constantly during a transition? How can I avoid that (Note: background cache is already enabled, otherwise drawBackground would be called ALL the time)? I somehow need to be able to paint the rescaled background into some kind of buffer which does not require to be changed, even when the sceneRect changes...
Some detail information about my case:
The background image has a dimension of 1920x1080 pixels. I also set a rectangle (0, 0, 1920, 1080) on myQscene->setSceneRect(..), otherwise the view would show all the menu screens at once (like a bird's eye view), rather than just one screen at a time. My application starts in WIndowed mode, but via a keyboard shortcut I can also go into full-screen mode.
Bookmarks