Adding a menu bar

We will now add the menu bar to our application. We use the class PySide.QtGui.QMenuBar for creating a menu bar. This class provides a horizontal menu bar to which the menu items can be added. You don't have to set a layout for menu bar. Different platforms use different layouts for the menu bar. In Windows system, the menu bar is usually anchored at the top of a window under the title bar. In the Macintosh system, the menu bar is usually anchored at the top of the screen. Linux systems have both these display formats depending on the GUI style. QMenuBar automatically sets its own geometry to the top of the parent widget and changes it appropriately whenever the parent is resized.

In the main window style applications, we use the PySide.QtGui.QMainWindow.menuBar() function to create a menu bar. This function will return an empty menu bar, which has QMainWindow as its parent. If you want all windows in a Mac application to share a single common menu bar, don't use this function to create it, because the menu bar created this way will have QMainWindow as its parent, instead you can create a menu bar with no parent by directly instantiating the QMenuBar class. The menu bar can also be set in the main window by using the PySide.QtGui.QMainWindow.setMenuBar(menubar) function, which takes a menu bar object as its parameter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.144.65