Update 菜单和工具栏.md

This commit is contained in:
maicss 2016-10-05 00:53:10 +08:00
parent 2f487ad4d7
commit 5c23e81bf9

View File

@ -179,24 +179,26 @@ if __name__ == '__main__':
ex = Example()
sys.exit(app.exec_())
```
In the above example, we create a simple toolbar. The toolbar has one tool action, an exit action which terminates the application when triggered.
上面的例子中,我们创建了一个工具栏。这个工具栏只有一个退出应用的动作。
```
exitAction = QAction(QIcon('exit24.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.triggered.connect(qApp.quit)
Similar to the menubar example above, we create an action object. The object has a label, icon, and a shorcut. A quit() method of the QtGui.QMainWindow is connected to the triggered signal.
```
和上面的菜单栏差不多这里使用了一个行为对象这个对象绑定了一个标签一个图标和一个快捷键。这些行为被触发的时候会调用QtGui.QMainWindow的quit方法退出应用。
```
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
Here we create a toolbar and plug and action object into it.
```
把工具栏展示出来。
程序展示:
![toolbar](./images/2-toolbar.png)
## 主窗口
In the last example of this section, we will create a menubar, toolbar, and a statusbar. We will also create a central widget.
主窗口就是上面三种栏目的总称,现在我们把上面的三种栏在一个应用里展示出来。
```
#!/usr/bin/python3
# -*- coding: utf-8 -*-
@ -254,11 +256,12 @@ if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
This code example creates a skeleton of a classic GUI application with a menubar, toolbar, and a statusbar.
```
```
textEdit = QTextEdit()
self.setCentralWidget(textEdit)
Here we create a text edit widget. We set it to be the central widget of the QMainWindow. The central widget will occupy all space that is left.
```
这里创建了一个文本编辑区域并把它放在QMainWindow的中间区域。这个组件或占满所有剩余的区域
程序展示: