I'm not very familiar with Qt, so please correct me if I'm wrong.
From what I've read QMainWindow (inherits QWidget) and QWidget both can receive/generate QEvents.
So if you enter (QEvent::Enter) your window you set the 2nd-QWidget's window id (QMainWindow?), which is now the receiver of the Magellan events.
If you now move (within the QMainWindow) to one of the both contained QWidgets the same thing happens again, correct?
In both cases your QMainWindow is/should be the receiver, which is just perfect.
If you leave one of the two QWidgets (QEvent::Leave) you call MagellanSetWindow() with InputFocus, which is still your QMainWindow since you're still within the window. So that behaviour is correct.
If you further leave your QMainWindow (again QEvent::Leave) and thus call MagellanSetWindow() with InputFocus again, the events should not be sent to your QMainWindow any longer, but to the window that has the new InputFocus.
Hope I could help!