ApplicationWindow MenuBar QML Type

ApplicationWindow QML Type

MenuBar QML Type

示例

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") }
        }
    }
}
  • 输出:

  • 其中 “&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
            }
        }
    }
}
  • 输出:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值