PySide.QtGui.QMenuBar class provides a horizontal menu bar.
菜单栏由下拉菜单项列表组成。添加菜单项采用 PySide.QtGui.QMenuBar.addMenu() . For example, asuming that menubar 是指针指向 PySide.QtGui.QMenuBar and fileMenu 是指针指向 PySide.QtGui.QMenu ,以下语句将菜单插入菜单栏:
menubar.addMenu(fileMenu)
The ampersand in the menu item's text sets Alt+F as a shortcut for this menu. (You can use “&&” to get a real ampersand in the menu bar.)
There is no need to lay out a menu bar. It automatically sets its own geometry to the top of the parent widget and changes it appropriately whenever the parent is resized.
In most main window style applications you would use the PySide.QtGui.QMainWindow.menuBar() function provided in PySide.QtGui.QMainWindow , adding PySide.QtGui.QMenu s to the menu bar and adding PySide.QtGui.QAction s to the pop-up menus.
范例 (来自 菜单 范例):
fileMenu = menuBar().addMenu(tr("&File"))
fileMenu.addAction(Act)
菜单项可以被移除采用 PySide.QtGui.QWidget.removeAction() .
Widgets can be added to menus by using instances of the PySide.QtGui.QWidgetAction class to hold them. These actions can then be inserted into menus in the usual way; see the PySide.QtGui.QMenu 文档编制了解更多细节。
Different platforms have different requirements for the appearance of menu bars and their behavior when the user interacts with them. For example, Windows systems are often configured so that the underlined character mnemonics that indicate keyboard shortcuts for items in the menu bar are only shown when the Alt key is pressed.
|
|
Plastique widget style , like most other styles, handles the Help menu in the same way as it handles any other menu. |
|
|
Motif widget style treats Help menus in a special way, placing them at right-hand end of the menu bar. |
PySide.QtGui.QMenuBar on Mac OS X is a wrapper for using the system-wide menu bar. If you have multiple menu bars in one dialog the outermost menu bar (normally inside a widget with widget flag Qt.Window ) will be used for the system-wide menu bar.
Qt for Mac OS X also provides a menu bar merging feature to make PySide.QtGui.QMenuBar conform more closely to accepted Mac OS X menu bar layout. The merging functionality is based on string matching the title of a PySide.QtGui.QMenu entry. These strings are translated (using QObject.tr() ) in the ” PySide.QtGui.QMenuBar ” context. If an entry is moved its slots will still fire as if it was in the original place. The table below outlines the strings looked for and where the entry is placed if matched:
| String matches | Placement | 注意事项 |
| about.* | Application Menu | About <application name> | The application name is fetched from the Info.plist file (see note below). If this entry is not found no About item will appear in the Application Menu. |
| config, options, setup, settings or preferences | Application Menu | Preferences | If this entry is not found the Settings item will be disabled |
| quit or exit | Application Menu | Quit <application name> | If this entry is not found a default Quit item will be created to call QApplication.quit() |
You can override this behavior by using the QAction.menuRole() 特性。
If you want all windows in a Mac application to share one menu bar, you must create a menu bar that does not have a parent. Create a parent-less menu bar this way:
menuBar = QMenuBar()
注意
Do not call QMainWindow.menuBar() to create the shared menu bar, because that menu bar will have the PySide.QtGui.QMainWindow as its parent. That menu bar would only be displayed for the parent PySide.QtGui.QMainWindow .
注意
The text used for the application name in the menu bar is obtained from the value set in the Info.plist file in the application's bundle. See Deploying an Application on Mac OS X 了解更多信息。
PySide.QtGui.QMenuBar on Windows CE is a wrapper for using the system-wide menu bar, similar to the Mac. This feature is activated for Windows Mobile and integrates PySide.QtGui.QMenuBar with the native soft keys. The left soft key can be controlled with QMenuBar.setDefaultAction() and the right soft key can be used to access the menu bar.
PySide.QtGui.QMenuBar.hovered() signal is not supported for the native menu integration. Also, it is not possible to display an icon in a native menu on Windows Mobile.
菜单 example shows how to use PySide.QtGui.QMenuBar and PySide.QtGui.QMenu 。其它 主窗口应用程序范例 还提供使用这些类的菜单。
另请参阅
PySide.QtGui.QMenu PySide.QtGui.QShortcut PySide.QtGui.QAction GUI 设计手册:菜单栏 菜单范例
| 参数: | parent – PySide.QtGui.QWidget |
|---|
构造菜单栏采用父级 parent .
| 参数: | arg__1 – PySide.QtCore.QPoint |
|---|---|
| 返回类型: | PySide.QtGui.QAction |
返回 PySide.QtGui.QAction at pt . Returns 0 if there is no action at pt 或者若位置拥有分隔符。
| 参数: | arg__1 – PySide.QtGui.QAction |
|---|---|
| 返回类型: | PySide.QtCore.QRect |
返回几何体对于动作 act 作为 PySide.QtCore.QRect .
| 返回类型: | PySide.QtGui.QAction |
|---|
返回 PySide.QtGui.QAction that is currently highlighted. A null pointer will be returned if no action is currently selected.
| 参数: | text – unicode |
|---|---|
| 返回类型: | PySide.QtGui.QAction |
这是重载函数。
此方便函数创建新动作,采用 text 。函数把新创建动作添加到菜单的动作列表,并返回它。
| 参数: |
|
|---|---|
| 返回类型: |
这是重载函数。
此方便函数创建新动作采用给定 text 。动作的 PySide.QtGui.QMenuBar.triggered() signal is connected to the receiver ‘s member slot. The function adds the newly created action to the menu's list of actions and returns it.
| 参数: |
|
|---|
| 参数: |
|
|---|---|
| 返回类型: |
追加新 PySide.QtGui.QMenu with icon and title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu.
| 参数: | menu – PySide.QtGui.QMenu |
|---|---|
| 返回类型: | PySide.QtGui.QAction |
追加 menu to the menu bar. Returns the menu's menuAction().
注意
返回的 PySide.QtGui.QAction 对象可以用于隐藏相应菜单。
| 参数: | title – unicode |
|---|---|
| 返回类型: | PySide.QtGui.QMenu |
追加新 PySide.QtGui.QMenu with title to the menu bar. The menu bar takes ownership of the menu. Returns the new menu.
| 返回类型: | PySide.QtGui.QAction |
|---|
将分隔符追加到菜单。
从菜单栏移除所有动作。
注意
On Mac OS X, menu items that have been merged to the system menu bar are not removed by this function. One way to handle this would be to remove the extra actions yourself. You can set the menu role on the different menus, so that you know ahead of time which menu items get merged and which do not. Then decide what to recreate or remove yourself.
| 参数: | corner – PySide.QtCore.Qt.Corner |
|---|---|
| 返回类型: | PySide.QtGui.QWidget |
| 参数: | action – PySide.QtGui.QAction |
|---|
| 参数: |
|
|---|
初始化 option 采用的值来自菜单栏和信息来自 action 。此方法对子类是有用的,当需要 PySide.QtGui.QStyleOptionMenuItem ,但不希望自己填充所有信息。
| 参数: |
|
|---|---|
| 返回类型: |
此方便函数插入 menu 前于动作 before 并返回菜单 menuAction()。
| 参数: | before – PySide.QtGui.QAction |
|---|---|
| 返回类型: | PySide.QtGui.QAction |
此方便函数创建新分隔符动作,即:动作采用 QAction.isSeparator() returning true. The function inserts the newly created action into this menu bar's list of actions before action before and returns it.
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds the popup orientation.
The default popup orientation. By default, menus pop “down” the screen. By setting the property to true, the menu will pop “up”. You might call this for menus that are below the document to which they refer.
If the menu would not fit on the screen, the other direction is used automatically.
| 返回类型: | PySide.QtCore.bool |
|---|
This property holds Whether or not a menubar will be used as a native menubar on platforms that support it.
This property specifies whether or not the menubar should be used as a native menubar on platforms that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms if this property is true, the menubar is used in the native menubar and is not in the window of its parent, if false the menubar remains in the window. On other platforms the value of this attribute has no effect.
The default is to follow whether the Qt.AA_DontUseNativeMenuBar attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.
另请参阅
void-qt-mac-set-native-menubar-bool-enable
| 返回类型: | PySide.QtCore.bool |
|---|
This function will update the current menu bar and set it as the active menu bar in the Menu Manager.
警告
This function is not portable.
另请参阅
QMenu.macMenu() QMenuBar.macMenu()
| 参数: | action – PySide.QtGui.QAction |
|---|
把目前突显动作设为 act .
| 参数: |
|
|---|
| 参数: | arg__1 – PySide.QtCore.bool |
|---|
This property holds the popup orientation.
The default popup orientation. By default, menus pop “down” the screen. By setting the property to true, the menu will pop “up”. You might call this for menus that are below the document to which they refer.
If the menu would not fit on the screen, the other direction is used automatically.
| 参数: | nativeMenuBar – PySide.QtCore.bool |
|---|
This property holds Whether or not a menubar will be used as a native menubar on platforms that support it.
This property specifies whether or not the menubar should be used as a native menubar on platforms that support it. The currently supported platforms are Mac OS X and Windows CE. On these platforms if this property is true, the menubar is used in the native menubar and is not in the window of its parent, if false the menubar remains in the window. On other platforms the value of this attribute has no effect.
The default is to follow whether the Qt.AA_DontUseNativeMenuBar attribute is set for the application. Explicitly settings this property overrides the presence (or abscence) of the attribute.
另请参阅
void-qt-mac-set-native-menubar-bool-enable
| 参数: | action – PySide.QtGui.QAction |
|---|