.ui.qml C++ 使用菜单栏例子
时间: 2023-06-11 11:10:13 浏览: 118
以下是一个简单的使用菜单栏的例子:
```
import QtQuick 2.15
import QtQuick.Controls 2.15
ApplicationWindow {
visible: true
width: 640
height: 480
title: "Menu Example"
menuBar: MenuBar {
Menu {
title: "File"
MenuItem {
text: "Open"
}
MenuItem {
text: "Save"
}
MenuItem {
text: "Exit"
onTriggered: Qt.quit()
}
}
Menu {
title: "Edit"
MenuItem {
text: "Copy"
}
MenuItem {
text: "Paste"
}
}
}
}
```
在上面的例子中,我们首先导入了必要的模块,然后创建了一个 `ApplicationWindow`。在窗口中,我们定义了一个 `MenuBar`,其中包含两个 `Menu`,分别是 "File" 和 "Edit"。每个菜单下面都包含了一些 `MenuItem`。当用户单击 "Exit" 菜单时,我们通过调用 `Qt.quit()` 来退出应用程序。
你可以将上面的代码复制到一个新的 `.ui.qml` 文件中并运行它,以查看它的工作原理。
阅读全文
相关推荐















