ApplicationWindow MenuBar QML Type

ApplicationWindow QML Type

  • 官方参考文档:https://doc.qt.io/qt-5/qml-qtquick-controls2-applicationwindow.html

ApplicationWindow MenuBar QML Type_第1张图片

MenuBar QML Type

  • 官方文档:https://doc.qt.io/qt-5/qml-qtquick-controls2-menubar.html

ApplicationWindow MenuBar QML Type_第2张图片

示例

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.5


ApplicationWindow {
    id: window
    width: 600
    height: 480
    visible: true

    menuBar: MenuBar {
        Menu {
            title: qsTr("&File")
            Action { text: qsTr("&New...") }
            Action { text: qsTr("&Open...") }
            Action { text: qsTr("&Save") }
            Action { text: qsTr("Save &As...") }
            MenuSeparator { }     //分割符号
            Action { text: qsTr("&Quit")
                onTriggered: {
                   Qt.quit()
                }
            }
        }
        Menu {
            title: qsTr("&Edit")
            Action { text: qsTr("Cu&t") }
            Action { text: qsTr("&Copy") }
            Action { text: qsTr("&Paste") }
        }
        Menu {
            title: qsTr("&Help")
            Action { text: qsTr("&About") }
        }
    }
}
  • 输出:

ApplicationWindow MenuBar QML Type_第3张图片

  • 其中 “&File” & 符号产生下划线

示例2

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Controls 2.5
import QtQuick.Controls 1.4 as Ctr_1_4
import QtQuick.Layouts 1.15

ApplicationWindow {
    id: window
    width: 600
    height: 480
    visible: true

    menuBar: MenuBar {
        Menu {
            title: qsTr("&File")
            Action { text: qsTr("&New...") }
            Action { text: qsTr("&Open...") }
            Action { text: qsTr("&Save") }
            Action { text: qsTr("Save &As...") }
            MenuSeparator { }     //分割符号
            Action { text: qsTr("&Quit")
                onTriggered: {
                   Qt.quit()
                }
            }
        }
        Menu {
            title: qsTr("&Edit")
            Action { text: qsTr("Cu&t") }
            Action { text: qsTr("&Copy") }
            Action { text: qsTr("&Paste") }
        }
        Menu {
            title: qsTr("&Help")
            Action { text: qsTr("&About") }
        }
    }

    header: ToolBar {
             RowLayout {
                 anchors.fill: parent
                 ToolButton {
                     text: qsTr("‹")
                     onClicked: stack.pop()
                 }
                 Label {
                     text: "标题"
                     font.bold: true
                     color: "red"
                     elide: Label.ElideRight
                     horizontalAlignment: Qt.AlignHCenter
                     verticalAlignment: Qt.AlignVCenter
                     Layout.fillWidth: true
                 }
                 ToolButton {
                     text: qsTr("⋮")
                     onClicked: menu.open()
                 }
             }
         }

    Rectangle{
        height: 50
        width: parent.width
        color: "grey"
    }

    footer: Ctr_1_4.StatusBar{
        Row{
            Label{
            text:"Menu " + ApplicationWindow.menuBar.count + " Count"
            color: "green"
            font.italic: true
            }
        }
    }
}
  • 输出:

ApplicationWindow MenuBar QML Type_第4张图片

你可能感兴趣的:(#,QT)