Important: Please read the Qt Code of Conduct -

Multiple QML files with menu and PyQt

  • Hello everyone! So I am new to the forums and I thank you all for reading this...

    I'm scratching my head at this condundrum I've ran into. I have multiple QML files. One is for the main window QML file which has an ApplicationWindow and MenuBar QObject like below...

    ApplicationWindow {
    id: main_window

    visible: true
    width: 700
    menuBar: MenuBar {
        id: main_bar
        Menu {
            title: qsTr("Run")
            MenuItem {
                signal open_diag_win()
                objectName: diag_win_dropdown
                text: qsTr("&Launch diagnostics Window")
                onTriggered: {
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();

    The code above is just a snippet, so I have this menu bar in the QML file which sends a signal to python. The signal from python then should get handled and then launch a new window on top of the main_window QML file called 'diagnostics_window'

    I know how to launch a single window with PyQt such as:

    app = Qapplication(sys.argv)
    engine = QmlApplicaitonEngine()

    #here's the connection being made from QML to python
    dropdown_menu = win.findChild(QObject, 'diag_win_dropdown')

    def launch_diag_win :

    Which then will launch the main window, but when that signal comes from QML and gets handled in Python which calls the python function 'launch_diag_win' , but how do I actually create another window when the application is already running? It has to be done mostly in python as the QML files should be as static as possible

    the diagnostics window is another QML file that has an ApplicationWindow object and its own QML code.

    So my thought process is, that there is a root QML main window with a child diagnostics window that pops up and the user can view and close. If they close it, it returns back to the root window (hopefully I am using the right vernacular here)

    I do hope I am asking this in the right area as I know this is QML but there is also python in what I'm asking...

    Any help or suggestions to guide me in the right direction would be greatly appreciated.

Log in to reply