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") }
}
}
}
示例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
}
}
}
}