calling raise() will set the focus on widget.

You will have check the geometry(). If the geometry's x
and y coordinates are negative, the widget is not on focus.
If the coordinates are positive, the widget is on top .

I have implemneted these method on QDockWidget. it may help you.