如何从 Qt Creator 编辑 App 菜单?

How to edit App menu from Qt Creator?

我在 Qt Creator 中启动 "QML App with controls" 项目。我看到我可以添加到 canvas 不同类型的控件,但我看不到如何在图形模式下编辑菜单,例如:文件、视图、编辑...在 canvas 的构造函数中很简单不存在,但 运行 个应用存在,例如 http://img.ctrlv.in/img/15/10/03/560f856edb26c.png

您可以在 main.qml 文件中创建 menu,这里是一个示例应用程序:

import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2

ApplicationWindow {
    title: qsTr("Hello World")
    width: 640
    height: 480
    visible: true

    menuBar: MenuBar {
        Menu {
            title: qsTr("&File")
            MenuItem {
                text: qsTr("&Open")
                onTriggered: messageDialog.show(qsTr("Open action triggered"));
            }
            MenuItem {
                text: qsTr("Save")
                onTriggered: messageDialog.show(qsTr("Save action triggered"));
            }
        }
        Menu {
            title: qsTr("&Help")
            MenuItem {
                text: qsTr("About")
                onTriggered: messageDialog.show(qsTr("About: test QML app with menu"));
            }
        }
    }

    MainForm {
        anchors.fill: parent
        button1.onClicked: messageDialog.show(qsTr("Button 1 pressed"))
        button2.onClicked: messageDialog.show(qsTr("Button 2 pressed"))
    }

    MessageDialog {
        id: messageDialog
        title: qsTr("Message Test")

        function show(caption) {
            messageDialog.text = caption;
            messageDialog.open();
        }
    }
}