Important: Please read the Qt Code of Conduct -

[Solved] Quick Menu is not modal?

  • I am substituting QML for QWidget in my app and was surprised to find that a Menu is not modal (whereas formerly I was using QMenu.exec() which is modal.) For example, after emitting a signal that causes Menu.popup() a print stmt prints and the menu is still visible. I don't see any property 'modal' and I don't see any signal from the menu to say the menu might have been canceled (user clicked outside the menu.) I could deal with non-modality (modeless) if only I knew when the menu was canceled (because then I could put my post-menu code after every action and after the cancel.) Maybe I am confused about the signal that causes the menu to popup, I assume it is synchronous (the emit doesn't return until the signal is handled) and I assume popup() is returning immediately.

    Am I missing something?

  • I found a workaround: do my post-context-menu work when focus is returned to another window. That is, connect a handler to QApp.focusWindowChanged.

    To be clear about the problem: my model layer (in C++ or Python) is emitting a signal to the UI layer (QML) to show a Menu (context menu) in a QQuickWindow. Execution continues in the model after emitting the signal (not synchronous.) The context menu receives focus (but I'm not sure what events the model continues to receive, i.e. it might be receiving mouseMoveEvents? That is, I'm not sure the context menu is modal in the sense that it is the only window receiving pointer and key events). After the user chooses an item of the context menu, or clicks outside of it, focus is returned to the main window and the model receives a focusWindowChanged signal. In the handler, the model unhighlights (unselects) the operand of the context menu.

Log in to reply