'Qt abstract buttom . How to draw the background in different z levels to avoid background overlaping with other buttons

I have design a Qt object derived from QAbstractButton. It has some transparent drawings that I use in the background and an opaque solid shape for the foreground.

The background is big, as a shadow, and two objects could be close and partially overlapped.

Foregrounds never overlap between then (by design) but background could overlap the other object (in both areas).

What I want to do is to draw foreground and background in different levels. I mean, first tp draw the backgrounds and then the foregrounds, in that way I will never overlap the foreground area.

Is it possible?

I'm using Qt 5.12.

Update: Adding some sketches

The current situation

Expected result

B2 yellow background is drawed over B1 solid foregraund, and it is not desired.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source