QMenuBar3qt
Horizontal menu bar
Usage
#include <qmenubar.h>
Inherits QFrame and QMenuData.
Public Members
QMenuBar ( QWidget * parent = 0, const char * name = 0 )
~QMenuBar ()
virtual void show ()
virtual void hide ()
virtual int heightForWidth ( int max_width ) const
enum Separator { Never = 0, InWindowsStyle = 1 }
Separator separator () const (obsolete)
virtual void setSeparator ( Separator when ) (obsolete)
void setDefaultUp ( bool )
bool isDefaultUp () const
Signals
void activated ( int id )
void highlighted ( int id )
Important Inherited Members
int insertItem ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QString & text, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, int id = -1, int index = -1 )
int insertItem ( const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( QWidget * widget, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, QCustomMenuItem * custom, int id = -1, int index = -1 )
int insertItem ( QCustomMenuItem * custom, int id = -1, int index = -1 )
int insertSeparator ( int index = -1 )
void removeItem ( int id )
void clear ()
bool isItemEnabled ( int id ) const
void setItemEnabled ( int id, bool enable )
bool isItemVisible ( int id ) const
void setItemVisible ( int id, bool visible )
Properties
bool defaultUp - the popup orientation
Separator separator - in which cases a menubar sparator is drawn (obsolete)
Protected Members
virtual void drawContents ( QPainter * p )
virtual void menuContentsChanged ()
virtual void menuStateChanged ()
Overview
The QMenuBar class provides a horizontal menu bar.
A menu bar consists of a list of pull-down menu items. You add menu items with insertItem(). For example, asuming that menubar is a pointer to a QMenuBar and filemenu is a pointer to a QPopupMenu, the following statement inserts the menu into the menu bar:
menubar->insertItem( "&File", 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.)
Items are either enabled or disabled. You toggle their state with setItemEnabled().
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.
Example of creating a menu bar with menu items (from menu/menu.cpp):
QPopupMenu *file = new QPopupMenu( this );
file->insertItem( p1, "&Open", this, SLOT(open()), CTRL+Key_O );
file->insertItem( p2, "&New", this, SLOT(news()), CTRL+Key_N );
menu = new QMenuBar( this );
menu->insertItem( "&File", file );
In most main window style applications you would use the menuBar() provided in QMainWindow, adding QPopupMenus to the menu bar and adding QActions to the popup menus.
Example (from action/application.cpp):
QPopupMenu * file = new QPopupMenu( this );
menuBar()->insertItem( "&File", file );
fileNewAction->addTo( file );
Menu items can have text and pixmaps (or iconsets), see the various insertItem() overloads, as well as separators, see insertSeparator(). You can also add custom menu items that are derived from QCustomMenuItem.
Menu items may be removed with removeItem() and enabled or disabled with setItemEnabled().
[Image Omitted]
[Image Omitted]
Member function documentation
bool defaultUp
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.
Set this property's value with setDefaultUp() and get this property's value with isDefaultUp().
Separator separator
This property holds in which cases a menubar sparator is drawn.
This property is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Set this property's value with setSeparator() and get this property's value with separator().
Releases
6 releases since Debian 2.2 (Potato); the text changed 4 times.