Jeff
Jeff

Reputation: 105

How do I get Qt Labs Qml Menubar working properly

I've followed all of the instructions I can find including:

Using "QApplication" instead of "QGuiApplication" in main.cpp

"QT += widgets" in .pro file (As a side note I get the same results whether I do the above or not - because I'm on macOS)

"import Qt.labs.platform 1.1 as Labs" in main.qml

Here's the code in my main.qml

Window {
id: window
visible: true
visibility: "Maximized"
width: 900
minimumWidth: 900
height: 700
minimumHeight: 700
title: qsTr("Crop Face")


Labs.MenuBar {
    id: menuBar


    Labs.Menu {
        id: editMenu
        title: qsTr("&Hi")
        // ...
    }

    Labs.Menu {
        id: viewMenu
        title: qsTr("&View")
        // ...
    }

    Labs.Menu {
        id: helpMenu
        title: qsTr("&Help")
        // ...
    }
}

And I get this result:

enter image description here

and:

enter image description here

Where on earth is "Emoji & Symbols" coming from !? And what happened to File, View and Help menu items? I have a commercial license and am using Qt 5.13 on MacOS Mojave. Interestingly if I change title: qsTr("&Edit") to title: qsTr("&Hi"), I don't get a Hi menu. Is there something I'm doing wrong or does Labs Menubar and Menu simply not work. If they don't work, how do I create a standard Mac native platform menubar?

Thanks Jeff

Upvotes: 1

Views: 689

Answers (1)

Jeff
Jeff

Reputation: 105

As deW1 pointed out in the comments above, at least one menuItem is required in a Menu for the menu to show up. Because "Emoji & Symbols" is added to Edit automatically by Mac, the Edit menu does show up, but none of the others do. I've added my new code below that works fine. Also note that because the "About" menuItem normally shows up under the application Menu, that is where it is placed and because that's the only menuItem in the File menu, the File menu doesn't need to show up. (This is how it should be - see image after code.)

ApplicationWindow {
id: window
visible: true
visibility: "Maximized"
width: 900
minimumWidth: 900
height: 700
minimumHeight: 700
title: qsTr("Crop Face")


Labs.MenuBar {
    id: menuBar

    Labs.Menu {
        id: fileMenu
        title: qsTr("File")

        Labs.MenuItem {
            text: qsTr("&About")
           // onTriggered: Qt.quit()
        }
    }

    Labs.Menu {
        id: windowMenu
        title: qsTr("&Window")

        Labs.MenuItem {
            text: qsTr("&Minimize")
            //onTriggered: messageDialog.show(qsTr("Open action triggered"))
        }
        Labs.MenuSeparator{}
        Labs.MenuItem {
            text: qsTr("Scroll Up")
            //onTriggered: messageDialog.show(qsTr("Open action triggered"))
        }
        Labs.MenuItem {
            text: qsTr("Scroll Down")
            //onTriggered: messageDialog.show(qsTr("Open action triggered"))
        }
    }



    Labs.Menu {
        id: helpMenu
        title: qsTr("&Help")
        Labs.MenuItem {
            text: qsTr("&View Website")
            //onTriggered: messageDialog.show(qsTr("Open action triggered"))
        }
    }
}

enter image description here

Upvotes: 2

Related Questions