Unsolved [Composing images] What is the best way to compose static and dynamic content in a drawing?
-
Until now, I have been drawing on a QWidget using QPainter. What I am basically drawing is similar to the Qt Analog Clock Example in that there are static parts of my drawing (like the markers indicating hours and minutes – these static parts don't change at all over the course of the program execution), as well as dynamic parts (like the clock faces – just changing much faster than those. Imagine a third hand in the linked to example displaying the seconds for a good facsimile).
Is there any fancy way to make something similar to the linked to example, but instead of redrawing everything on each refresh to only redraw certain parts? Is there maybe a way of composing images of several layers so that one could update each (partially transparent) layer at its own pace?
-
@NWeyand said in [Composing images] What is the best way to compose static and dynamic content in a drawing?:
Is there any fancy way to make something similar to the linked to example, but instead of redrawing everything on each refresh to only redraw certain parts?
You can cache all of the static parts. Draw them once and keep the image; then draw the dynamic content on each tick.
Is there maybe a way of composing images of several layers so that one could update each (partially transparent) layer at its own pace?
Yes, see the composition modes' docs and examples.
-
After some more research on this topic, I have decided to switch to a solution using several QPixMaps, all of which are initialized at startup and only some of which are updated at a later time. These are handled as QGraphicsPixmapItem and composed in a QGraphicsScene. This also covers nicely for the fact, that I was moving one of the to be composed pictures around on each redraw.
Any comments / pitfalls I need to be aware of?
-
Not really, no. It sounds like a good plan. Only thing that might be considered a "pitfall" is probably if you want to thread the painting later, then pixmaps aren't suitable, but I suppose you could switch to
QImage
rather easily if that requirement arises.PS.
You might also want to try QML and QtQuick, which supposedly performs much better than the graphics view framework.Cheers!