I searched a bit about whether Qt has true layering for opacity, and found a post in Qt Blog by Andreas Aardal Hanssen:
https://blog.qt.io/blog/2009/04/23/layered-rendering-part-2-it-helps-solve-many-problems/
He says the only way to do it is using off-screen rendering.
By rendering the “green sub-tree” into a separate layer, we can combine all items and apply one uniform opacity as part of composing these items together. In my last blog I wrote about off-screen rendering. This work has progressed and is in quite a usable state (although the code is really ugly). It works! The rendering output for the same application as the above looks like this.
The link to the off-screen rendering solution is https://blog.qt.io/blog/2009/02/27/braindump-graphics-view-and-the-joys-of-off-screen-rendering.
I think the idea is that you render each layer separately to a pixmap. The items in that layer are opaque relative to each other. Then you render the layers themselves with transparency relative to each other.
Items in the same layer are opaque relative to each other, but transparent relative to items in the other layers.
The link talks about some prototype project that uses DeepItemCoordinateCache, which renders an item and its children to an offscreen buffer, then renders that buffer. This would achieve the desired effect.
Collapsing a subtree into a single offscreen buffer is possible. I’ve spent two days this week researching it, wrote some code, and ended up with a prototype that’s so ugly I don’t want to share it just yet. But I’ve seen that it’s perfectly possible without messing up QGV’s internals. I dubbed two new cache modes:
DeepItemCoordinateCache – caches the item and “all” children, no repaints for “any” child if the parent is transformed
DeepDeviceCoordinateCache – save for DeviceCoordinateCache
Unfortunately, I don't know if his prototype code is available anywhere. He implies it's inside the Embedded Dialogs example at https://doc.qt.io/qt-5/qtwidgets-graphicsview-embeddeddialogs-example.html, so maybe you should search there.