Solved!

The solution was not in the widget itself, but in the QWorkspace that owned the widget.

I used workspace->activeWindow() and compared it with each of the widgets in the workspace->windowList() and found out which had "focus".