c++ - QGraphicsPathItem overlapping semitransparent path become more opaque -


i'm drawing semitransparent paths qgraphicspathitems have issue when 2 paths overlap, become more opaque, them keep same level of transparency, no matter how many paths overlap.

on left side 2 separate paths, become more opaque. on right, single path crossing on itself, same level of transparency, effect achieve several paths.

overlapping paths

is possible achieve that?

i searched bit whether qt has true layering opacity, , found post in qt blog andreas aardal hanssen:

https://blog.qt.io/blog/2009/04/23/layered-rendering-part-2-it-helps-solve-many-problems/

he says way using off-screen rendering.

by rendering “green sub-tree” separate layer, can combine items , apply 1 uniform opacity part of composing these items together. in last blog wrote off-screen rendering. work has progressed , in quite usable state (although code ugly). works! rendering output same application above looks this.

the link off-screen rendering solution https://blog.qt.io/blog/2009/02/27/braindump-graphics-view-and-the-joys-of-off-screen-rendering.

i think idea render each layer separately pixmap. items in layer opaque relative each other. render layers transparency relative each other.

items in same layer opaque relative each other, transparent relative items in other layers.

the link talks prototype project uses deepitemcoordinatecache, renders item , children offscreen buffer, renders buffer. achieve desired effect.

collapsing subtree single offscreen buffer possible. i’ve spent 2 days week researching it, wrote code, , ended prototype that’s ugly don’t want share just yet. 😉 i’ve seen it’s possible without messing qgv’s internals. dubbed 2 new cache modes:

deepitemcoordinatecache – caches item , “all” children, no repaints “any” child if parent transformed deepdevicecoordinatecache – save devicecoordinatecache

unfortunately, don't know if prototype code available anywhere. implies it's inside embedded dialogs example @ https://doc.qt.io/qt-5/qtwidgets-graphicsview-embeddeddialogs-example.html, maybe should search there.


Comments