Steps to reproduce:
- Build and run the attached program.
- Select menu item Main Window > Open Second Window.
- Click on the blue area in the second window.
- The menu bar changes from the second window's to the global app's.
At least in the original application I was working with (I didn't try with the attached test application), when the focus goes wrong, the application's focus object is QQuickRootItem and the focus window is a QQuickView. When the focus is correct, the focus object is my QMainWIndow subclass and the focus window is a QWidgetWindow.
I can avoid the problem by replacing the QQuickView and QWidget::createWindowContainer() with a QQuickWidget.
However, will QQuickWidget continue to work? This blog post from 2014 strongly advises using QQuickWidget over QWidget::createWindowContainer(). But this bug report from 2020 recommends QWidget::createWindowContainer() and says QQuickWidget may become deprecated.