# QMenuBar Class Reference

The QMenuBar class provides a horizontal menu bar. More...

`#include <qmenubar.h>`

Inherits QFrame and QMenuData.

List of all member functions.

## Public Members

- QMenuBar ( QWidget * parent=0, const char * name=0 )
- ~QMenuBar ()
- virtual void updateItem ( int id )
- virtual void show ()
- virtual void hide ()
- virtual bool eventFilter ( QObject *, QEvent * )
- int heightForWidth ( int ) const
- Separator separator () const
- void setSeparator ( Separator when )

## Signals

- void activated ( int itemId )
- void highlighted ( int itemId )

## Protected Members

- virtual void drawContents ( QPainter * )
- virtual void fontChange ( const QFont & )
- virtual void mousePressEvent ( QMouseEvent * )
- virtual void mouseReleaseEvent ( QMouseEvent * )
- virtual void mouseMoveEvent ( QMouseEvent * )
- virtual void keyPressEvent ( QKeyEvent * )
- virtual void resizeEvent ( QResizeEvent * )
- virtual void leaveEvent ( QEvent * )
- virtual void menuContentsChanged ()
- virtual void menuStateChanged ()

## Detailed Description

The QMenuBar class provides a horizontal menu bar.

It automatically sets its own geometry to the top of the parent widget and changes appropriately it when the parent widget is resized.

menu/menu.cpp is a typical example of QMenuBar and QPopupMenu use.

See also: QPopupMenu and GUI Design Handbook: Menu Bar

Examples: grapher/grapher.cpp xform/xform.cpp menu/menu.cpp progress/progress.cpp layout/layout.cpp showimg/showimg.cpp widgets/widgets.cpp

## Member Function Documentation

### QMenuBar::QMenuBar ( QWidget * parent=0, const char * name=0 )

Creates a menu bar with a parent and a name.

### QMenuBar::~QMenuBar ()

Destroys the menu bar.

### void QMenuBar::activated ( int id ) `[signal]`

This signal is emitted when a menu item is selected; id is the id of the selected item.

Normally, you will connect each menu item to a single slot using QMenuData::insertItem(), but sometimes you will want to connect several items to a single slot (most often if the user selects from an array). This signal is handy in such cases.

See also: highlighted() and QMenuData::insertItem().

### void QMenuBar::drawContents ( QPainter * p ) `[virtual protected]`

Called from QFrame::paintEvent().

Reimplemented from QFrame.

### bool QMenuBar::eventFilter ( QObject * object, QEvent * event ) `[virtual]`

This function is used to adjust the menu bar's geometry to the parent widget's. Note that this is not part of the public interface - the function is `public` only because QObject::eventFilter() is.

Reimplemented from QObject.

### void QMenuBar::fontChange ( const QFont & ) `[virtual protected]`

For internal use only.

Reimplemented from QWidget.

### int QMenuBar::heightForWidth ( int max_width ) const

Returns the height that the menu would resize itself to if its parent (and hence itself) resized to the given width. This can be useful for simple layout tasks where the height of the menubar is needed after items have been inserted. See examples/showimg/showimg.cpp for an example of the usage.

### void QMenuBar::hide () `[virtual]`

Reimplements QWidget::hide() in order to deselect any selected item.

Examples: grapher/grapher.cpp

Reimplemented from QWidget.

### void QMenuBar::highlighted ( int id ) `[signal]`

This signal is emitted when a menu item is highlighted; id is the id of the highlighted item.

Normally, you will connect each menu item to a single slot using QMenuData::insertItem(), but sometimes you will want to connect several items to a single slot (most often if the user selects from an array). This signal is handy in such cases.

See also: activated() and QMenuData::insertItem().

### void QMenuBar::keyPressEvent ( QKeyEvent * e ) `[virtual protected]`

Handles key press events for the menu bar.

Reimplemented from QWidget.

### void QMenuBar::leaveEvent ( QEvent * e ) `[virtual protected]`

Handles leave events for the menu bar.

Reimplemented from QWidget.

### void QMenuBar::menuContentsChanged () `[virtual protected]`

Recomputes the menu bar's display data according to the new contents.

You should never need to call this, it is called automatically by QMenuData whenever it needs to be called.

Reimplemented from QMenuData.

### void QMenuBar::menuStateChanged () `[virtual protected]`

Recomputes the menu bar's display data according to the new state.

You should never need to call this, it is called automatically by QMenuData whenever it needs to be called.

Reimplemented from QMenuData.

### void QMenuBar::mouseMoveEvent ( QMouseEvent * e ) `[virtual protected]`

Handles mouse move events for the menu bar.

Reimplemented from QWidget.

### void QMenuBar::mousePressEvent ( QMouseEvent * e ) `[virtual protected]`

Handles mouse press events for the menu bar.

Reimplemented from QWidget.

### void QMenuBar::mouseReleaseEvent ( QMouseEvent * e ) `[virtual protected]`

Handles mouse release events for the menu bar.

Reimplemented from QWidget.

### void QMenuBar::resizeEvent ( QResizeEvent * ) `[virtual protected]`

Handles resize events for the menu bar.

Reimplemented from QWidget.

### QMenuBar::Separator QMenuBar::separator() const

Returns the currently set separator usage

### void QMenuBar::setSeparator ( Separator when )

When a menubar is used above an unframed widget, it may look better with a separating line when displayed with WindowsStyle.

This function sets the usage of such a separator to appear either QMenuBar::Never, or QMenuBar::InWindowsStyle.

The default is QMenuBar::Never.

Examples: layout/layout.cpp widgets/widgets.cpp

### void QMenuBar::show () `[virtual]`

Reimplements QWidget::show() in order to set up the correct keyboard accelerators and raise itself to the top of the widget stack.

Examples: grapher/grapher.cpp

Reimplemented from QWidget.

### void QMenuBar::updateItem ( int ) `[virtual]`

For internal use only.

Reimplemented from QMenuData.

Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):

This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.

It was generated from the following files:

- qmenubar.h: 1998/08/21
- qmenubar.cpp: 1999/02/25