-1

Is there any way to add standard About and Preferences... menu items using Qt Quick Controls 2?

Mac OS menu bar

Qt version 5.7, macOS Sierra 10.12.2

Community
  • 1
  • 1
Kamil Zaripov
  • 904
  • 11
  • 33

1 Answers1

1

Check out Menu and MenuItem from Controls 2.

Button {
    id: fileButton
    text: "File"
    onClicked: menu.open()

    Menu {
        id: menu
        y: fileButton.height

        MenuItem {
            text: "New..."
        }
        MenuItem {
            text: "Open..."
        }
        MenuItem {
            text: "Save"
        }
    }
}

Controls 2 doesn't appear to have a MenuBar element thou. But it is essentially just a row of buttons which open menus plus a filler for the bar, anchored to the top of the window. So you can easily do it yourself.

The downside of using controls 2 is that it doesn't seem to support native menu styles.

Good news - the upcoming 5.8 release will come with the Qt.labs.platform module, which provides platform native controls, there is a menu bar, menu, menu item, menu groups and separators.

dtech
  • 47,916
  • 17
  • 112
  • 190
  • Yes, I know how to make window/view/dialog. But how to add menu item into menubar? – Kamil Zaripov Jan 18 '17 at 06:23
  • 1
    Set MenuItem.PreferencesRole for a MenuItem from Qt Labs Platform: https://doc-snapshots.qt.io/qt5-5.8/qml-qt-labs-platform-menuitem.html#role-prop – jpnurmi Jan 19 '17 at 16:50