目录
ApplicationWindow
对应QMainWindow
,提供顶层应用程序窗口
MenuBar
提供窗口顶部横向的菜单栏,下面例子点击响应的MenuBarItem会触发Triggered信号,QML的消息响应函数是On+信号名称
StatusBar
提供底部状态栏
toolBar
提供工具栏,可以添加ToolButton
和其它组件
Action
提供能够绑定到导航和视图的抽象的用户界面动作
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
statusBar: StatusBar {
RowLayout {
anchors.fill: parent
Label { text: "Read Only" }
}
}
toolBar:ToolBar {
RowLayout {
anchors.fill: parent
ToolButton {
iconSource: "qrc:/new.png"
}
ToolButton {
iconSource: "qrc:/open.png"
}
ToolButton {
iconSource: "qrc:/save-as.png"
}
Item { Layout.fillWidth: true }
CheckBox {
text: "Enabled"
checked: true
Layout.alignment: Qt.AlignRight
}
}
}
Button {action:copyAction;}
menuBar: MenuBar{
Menu {
title: "文件";
MenuItem{
id: menuItem
action: copyAction
text: "退出";
onTriggered: Qt.quit();
}
}
Menu {
title: "帮助";
MenuItem{
text: "关于";
action:cutAction
onTriggered: root.showAbout();
}
MenuItem{
text: "官网";
action:pasteAction
onTriggered: Qt.openUrlExternally("http://www.baidu.com");
}
}
}
Action {
id: copyAction
text: "&Copy"
shortcut: StandardKey.Copy
iconName: "edit-copy"
enabled: (!!activeFocusItem && !!activeFocusItem["copy"])
onTriggered: activeFocusItem.copy()
}
Action {
id: cutAction
text: "Cu&t"
shortcut: StandardKey.Cut
iconName: "edit-cut"
enabled: (!!activeFocusItem && !!activeFocusItem["cut"])
onTriggered: activeFocusItem.cut()
}
Action {
id: pasteAction
text: "&Paste"
shortcut: StandardKey.Paste
iconName: "edit-paste"
enabled: (!!activeFocusItem && !!activeFocusItem["paste"])
onTriggered: activeFocusItem.paste()
}
}
关于layout可以看官网Layout QML Type | Qt Quick 5.15.13,也是布局管理,可以认为是父组件里子控件的布局。
未完待续。。。