Doesn't work for me. visRegn.boundingRect() and pWidget->rect() are always equal and visRegn.rects().count() always return 4 when the window is visible (setVisible(true))
I tried to implement next..

I have a window and a tray icon. There are 3 possible actions on click on the tray.
1) raise the window to front if it's behind of some others windows
2) show and raise it if it's currently in the hidden state.
3) hide it if it's currently fully visible.

I guess there is no other Qt way to do this. So may be it's better to implement DE specific tray plugins for my application. For example KDE has a concept of "associated widget" in their KStatusNotifierItem. According to comments in the code it seems it does exactly what I want.