Eneboo - Documentación para desarrolladores
Tipos públicos | Señales | Métodos públicos | Métodos protegidos | Propiedades | Amigas
Referencia de la Clase QMenuBar

The QMenuBar class provides a horizontal menu bar. Más...

#include <qmenubar.h>

Diagrama de herencias de QMenuBar
QFrame QMenuData QFrame QMenuData QWidget QWidget QWidget QWidget QPaintDevice QObject QPaintDevice QObject QPaintDevice QObject QPaintDevice QObject QPaintDevice QObject QPaintDevice QObject QPaintDevice QObject QPaintDevice QObject MenuBarEditor MyMenuBar QtcMenuBar

Lista de todos los miembros.

Tipos públicos

enum  Separator { Never = 0, InWindowsStyle = 1, Never = 0, InWindowsStyle = 1 }
enum  Separator { Never = 0, InWindowsStyle = 1, Never = 0, InWindowsStyle = 1 }

Señales

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

Métodos públicos

 QMenuBar (QWidget *parent=0, const char *name=0)
 ~QMenuBar ()
void updateItem (int id)
void show ()
void hide ()
bool eventFilter (QObject *, QEvent *)
int heightForWidth (int) const
Separator separator () const
virtual void setSeparator (Separator when)
void setDefaultUp (bool)
bool isDefaultUp () const
bool customWhatsThis () const
QSize sizeHint () const
QSize minimumSize () const
QSize minimumSizeHint () const
void activateItemAt (int index)
 QMenuBar (QWidget *parent=0, const char *name=0)
 ~QMenuBar ()
void updateItem (int id)
void show ()
void hide ()
bool eventFilter (QObject *, QEvent *)
int heightForWidth (int) const
Separator separator () const
virtual void setSeparator (Separator when)
void setDefaultUp (bool)
bool isDefaultUp () const
bool customWhatsThis () const
QSize sizeHint () const
QSize minimumSize () const
QSize minimumSizeHint () const
void activateItemAt (int index)

Métodos protegidos

void drawContents (QPainter *)
void fontChange (const QFont &)
void mousePressEvent (QMouseEvent *)
void mouseReleaseEvent (QMouseEvent *)
void mouseMoveEvent (QMouseEvent *)
void keyPressEvent (QKeyEvent *)
void focusInEvent (QFocusEvent *)
void focusOutEvent (QFocusEvent *)
void resizeEvent (QResizeEvent *)
void leaveEvent (QEvent *)
void menuContentsChanged ()
void menuStateChanged ()
void styleChange (QStyle &)
int itemAtPos (const QPoint &)
void hidePopups ()
QRect itemRect (int item)
void drawContents (QPainter *)
void fontChange (const QFont &)
void mousePressEvent (QMouseEvent *)
void mouseReleaseEvent (QMouseEvent *)
void mouseMoveEvent (QMouseEvent *)
void keyPressEvent (QKeyEvent *)
void focusInEvent (QFocusEvent *)
void focusOutEvent (QFocusEvent *)
void resizeEvent (QResizeEvent *)
void leaveEvent (QEvent *)
void menuContentsChanged ()
void menuStateChanged ()
void styleChange (QStyle &)
int itemAtPos (const QPoint &)
void hidePopups ()
QRect itemRect (int item)

Propiedades

Separator separator
 in which cases a menubar sparator is drawn
bool defaultUp
 the popup orientation

Amigas

class QPopupMenu

Descripción detallada

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.

insertItem removeItem clear insertSeparator setItemEnabled isItemEnabled setItemVisible isItemVisible

Example of creating a menu bar with menu items (from menu/menu.cpp): menu/menu.cpp file = new QPopupMenu Key_O new QMenuBar insertItem

In most main window style applications you would use the menuBar() provided in QMainWindow, adding {QPopupMenu}s to the menu bar and adding {QAction}s to the popup menus.

Example (from action/application.cpp): action/application.cpp file = new QPopupMenu fileNewAction

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().

qmenubar-m.png
qmenubar-w.png

Documentación de las enumeraciones miembro de la clase

This enum type is used to decide whether QMenuBar should draw a separator line at its bottom.

Never In many applications there is already a separator, and having two looks wrong.

InWindowsStyle In some other applications a separator looks good in Windows style, but nowhere else.

Valores de enumeraciones:
Never 
InWindowsStyle 
Never 
InWindowsStyle 
Valores de enumeraciones:
Never 
InWindowsStyle 
Never 
InWindowsStyle 

Documentación del constructor y destructor

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

Constructs a menu bar called name with parent parent.

QMenuBar::~QMenuBar ( )

Destroys the menu bar.

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

Documentación de las funciones miembro

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 useful in such cases.

Ver también:
highlighted(), QMenuData::insertItem()
void QMenuBar::activated ( int  itemId) [signal]
void QMenuBar::activateItemAt ( int  index) [virtual]

Activates the menu item at position index.

If the index is invalid (for example, -1), the object itself is deactivated.

Reimplementado de QMenuData.

void QMenuBar::activateItemAt ( int  index) [virtual]

Reimplementado de QMenuData.

bool QMenuBar::customWhatsThis ( ) const [virtual]

Reimplementado de QWidget.

bool QMenuBar::customWhatsThis ( ) const [virtual]

Reimplementado de QWidget.

void QMenuBar::drawContents ( QPainter p) [protected, virtual]

Called from QFrame::paintEvent(). Draws the menu bar contents using painter p.

Reimplementado de QFrame.

void QMenuBar::drawContents ( QPainter ) [protected, virtual]

Virtual function that draws the contents of the frame.

The QPainter is already open when you get it, and you must leave it open. Painter transformations are switched off on entry. If you transform the painter, remember to take the frame into account and reset transformation before returning.

This function is reimplemented by subclasses that draw something inside the frame. It should only draw inside contentsRect(). The default function does nothing.

Ver también:
contentsRect(), QPainter::setClipRect()

Reimplementado de QFrame.

bool QMenuBar::eventFilter ( QObject ,
QEvent  
) [virtual]

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event e, out, i.e. stop it being handled further, return TRUE; otherwise return FALSE.

Example:

    class MyMainWindow : public QMainWindow
    {
    public:
        MyMainWindow( QWidget *parent = 0, const char *name = 0 );

    protected:
        bool eventFilter( QObject *obj, QEvent *ev );

    private:
        QTextEdit *textEdit;
    };

    MyMainWindow::MyMainWindow( QWidget *parent, const char *name )
        : QMainWindow( parent, name )
    {
        textEdit = new QTextEdit( this );
        setCentralWidget( textEdit );
        textEdit->installEventFilter( this );
    }

    bool MyMainWindow::eventFilter( QObject *obj, QEvent *ev )
    {
        if ( obj == textEdit ) {
            if ( e->type() == QEvent::KeyPress ) {
                QKeyEvent *k = (QKeyEvent*)ev;
                qDebug( "Ate key press %d", k->key() );
                return TRUE;
            } else {
                return FALSE;
            }
        } else {
            // pass the event on to the parent class
            return QMainWindow::eventFilter( obj, ev );
        }
    }

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

Atención:
If you delete the receiver object in this function, be sure to return TRUE. Otherwise, Qt will forward the event to the deleted object and the program might crash.
Ver también:
installEventFilter()

Reimplementado de QObject.

Reimplementado en MenuBarEditor.

bool QMenuBar::eventFilter ( QObject ,
QEvent  
) [virtual]

Filters events if this object has been installed as an event filter for the watched object.

In your reimplementation of this function, if you want to filter the event e, out, i.e. stop it being handled further, return TRUE; otherwise return FALSE.

Example:

    class MyMainWindow : public QMainWindow
    {
    public:
        MyMainWindow( QWidget *parent = 0, const char *name = 0 );

    protected:
        bool eventFilter( QObject *obj, QEvent *ev );

    private:
        QTextEdit *textEdit;
    };

    MyMainWindow::MyMainWindow( QWidget *parent, const char *name )
        : QMainWindow( parent, name )
    {
        textEdit = new QTextEdit( this );
        setCentralWidget( textEdit );
        textEdit->installEventFilter( this );
    }

    bool MyMainWindow::eventFilter( QObject *obj, QEvent *ev )
    {
        if ( obj == textEdit ) {
            if ( e->type() == QEvent::KeyPress ) {
                QKeyEvent *k = (QKeyEvent*)ev;
                qDebug( "Ate key press %d", k->key() );
                return TRUE;
            } else {
                return FALSE;
            }
        } else {
            // pass the event on to the parent class
            return QMainWindow::eventFilter( obj, ev );
        }
    }

Notice in the example above that unhandled events are passed to the base class's eventFilter() function, since the base class might have reimplemented eventFilter() for its own internal purposes.

Atención:
If you delete the receiver object in this function, be sure to return TRUE. Otherwise, Qt will forward the event to the deleted object and the program might crash.
Ver también:
installEventFilter()

Reimplementado de QObject.

Reimplementado en MenuBarEditor.

void QMenuBar::focusInEvent ( QFocusEvent ) [protected, virtual]

Reimplementado de QWidget.

void QMenuBar::focusInEvent ( QFocusEvent ) [protected, virtual]

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.

A widget normally must setFocusPolicy() to something other than NoFocus in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for toplevel widgets that do not specify a focusPolicy() ). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.

Ver también:
focusOutEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event(), QFocusEvent

Reimplementado de QWidget.

void QMenuBar::focusOutEvent ( QFocusEvent ) [protected, virtual]

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::focusOutEvent ( QFocusEvent ) [protected, virtual]

This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.

A widget normally must setFocusPolicy() to something other than NoFocus in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)

The default implementation updates the widget (except for toplevel widgets that do not specify a focusPolicy() ). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.

Ver también:
focusInEvent(), setFocusPolicy(), keyPressEvent(), keyReleaseEvent(), event(), QFocusEvent

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::fontChange ( const QFont oldFont) [protected, virtual]

This virtual function is called from setFont(). oldFont is the previous font; you can get the new font from font().

Reimplement this function if your widget needs to know when its font changes. You will almost certainly need to update the widget using update().

The default implementation updates the widget including its geometry.

Ver también:
setFont(), font(), update(), updateGeometry()

Reimplementado de QWidget.

void QMenuBar::fontChange ( const QFont oldFont) [protected, virtual]

This virtual function is called from setFont(). oldFont is the previous font; you can get the new font from font().

Reimplement this function if your widget needs to know when its font changes. You will almost certainly need to update the widget using update().

The default implementation updates the widget including its geometry.

Ver también:
setFont(), font(), update(), updateGeometry()

Reimplementado de QWidget.

int QMenuBar::heightForWidth ( int  w) const [virtual]

Returns the preferred height for this widget, given the width w. The default implementation returns 0, indicating that the preferred height does not depend on the width.

Atención:
Does not look at the widget's layout.

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

int QMenuBar::heightForWidth ( int  max_width) const [virtual]

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

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::hide ( ) [virtual]

Hides the widget.

You almost never have to reimplement this function. If you need to do something after a widget is hidden, use hideEvent() instead.

Ver también:
hideEvent(), isHidden(), show(), showMinimized(), isVisible(), close()

Reimplementado de QWidget.

void QMenuBar::hide ( ) [virtual]

Reimplements QWidget::hide() in order to deselect any selected item, and calls setUpLayout() for the main window.

Reimplementado de QWidget.

void QMenuBar::hidePopups ( ) [protected]
void QMenuBar::hidePopups ( ) [protected]
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 useful in such cases.

Ver también:
activated(), QMenuData::insertItem()
void QMenuBar::highlighted ( int  itemId) [signal]
bool QMenuBar::isDefaultUp ( ) const
bool QMenuBar::isDefaultUp ( ) const
int QMenuBar::itemAtPos ( const QPoint pos_) [protected]
int QMenuBar::itemAtPos ( const QPoint ) [protected]
QRect QMenuBar::itemRect ( int  item) [protected]
QRect QMenuBar::itemRect ( int  item) [protected]
void QMenuBar::keyPressEvent ( QKeyEvent e) [protected, virtual]

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::keyPressEvent ( QKeyEvent e) [protected, virtual]

This event handler, for event e, can be reimplemented in a subclass to receive key press events for the widget.

A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.

If you reimplement this handler, it is very important that you explicitly ignore the event if you do not understand it, so that the widget's parent can interpret it; otherwise, the event will be implicitly accepted. Although top-level widgets are able to choose whether to accept or ignore unknown events because they have no parent widgets that could otherwise handle them, it is good practice to explicitly ignore events to make widgets as reusable as possible.

The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.

Ver también:
keyReleaseEvent(), QKeyEvent::ignore(), setFocusPolicy(), focusInEvent(), focusOutEvent(), event(), QKeyEvent

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::leaveEvent ( QEvent e) [protected, virtual]

Reimplementado de QWidget.

void QMenuBar::leaveEvent ( QEvent ) [protected, virtual]

This event handler can be reimplemented in a subclass to receive widget leave events.

A leave event is sent to the widget when the mouse cursor leaves the widget.

Ver también:
enterEvent(), mouseMoveEvent(), event()

Reimplementado de QWidget.

void QMenuBar::menuContentsChanged ( ) [protected, virtual]

Virtual function; notifies subclasses that one or more items have been inserted or removed.

Reimplementado de QMenuData.

void QMenuBar::menuContentsChanged ( ) [protected, virtual]

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.

Reimplementado de QMenuData.

void QMenuBar::menuStateChanged ( ) [protected, virtual]

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.

Reimplementado de QMenuData.

void QMenuBar::menuStateChanged ( ) [protected, virtual]

Virtual function; notifies subclasses that one or more items have changed state (enabled/disabled or checked/unchecked).

Reimplementado de QMenuData.

QSize QMenuBar::minimumSize ( ) const

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

QSize QMenuBar::minimumSize ( ) const

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

QSize QMenuBar::minimumSizeHint ( ) const [virtual]

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

QSize QMenuBar::minimumSizeHint ( ) const [virtual]

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::mouseMoveEvent ( QMouseEvent e) [protected, virtual]

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::mouseMoveEvent ( QMouseEvent e) [protected, virtual]

This event handler, for event e, can be reimplemented in a subclass to receive mouse move events for the widget.

If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.

QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.

Ver también:
setMouseTracking(), mousePressEvent(), mouseReleaseEvent(), mouseDoubleClickEvent(), event(), QMouseEvent

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::mousePressEvent ( QMouseEvent e) [protected, virtual]

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::mousePressEvent ( QMouseEvent e) [protected, virtual]

This event handler, for event e, can be reimplemented in a subclass to receive mouse press events for the widget.

If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.

The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

Ver también:
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::mouseReleaseEvent ( QMouseEvent e) [protected, virtual]

This event handler, for event e, can be reimplemented in a subclass to receive mouse release events for the widget.

Ver también:
mouseReleaseEvent(), mouseDoubleClickEvent(), mouseMoveEvent(), event(), QMouseEvent

Reimplementado de QWidget.

void QMenuBar::mouseReleaseEvent ( QMouseEvent e) [protected, virtual]

Reimplementado de QWidget.

void QMenuBar::resizeEvent ( QResizeEvent e) [protected, virtual]

Processes the resize event e.

Adjusts the frame rectangle for the resized widget. The frame rectangle is elastic, and the surrounding area is static.

The resulting frame rectangle may be null or invalid. You can use setMinimumSize() to avoid those possibilities.

Nothing is done if the frame rectangle is a null rectangle already.

Reimplementado de QFrame.

Reimplementado en MenuBarEditor.

void QMenuBar::resizeEvent ( QResizeEvent e) [protected, virtual]

Reimplementado de QFrame.

Reimplementado en MenuBarEditor.

Separator QMenuBar::separator ( ) const
Separator QMenuBar::separator ( ) const
void QMenuBar::setDefaultUp ( bool  on)
void QMenuBar::setDefaultUp ( bool  )
virtual void QMenuBar::setSeparator ( Separator  when) [virtual]
void QMenuBar::setSeparator ( Separator  when) [virtual]
void QMenuBar::show ( ) [virtual]

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

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

void QMenuBar::show ( ) [virtual]

Shows the widget and its child widgets.

If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown.

You almost never have to reimplement this function. If you need to change some settings before a widget is shown, use showEvent() instead. If you need to do some delayed initialization use polish().

Ver también:
showEvent(), hide(), showMinimized(), showMaximized(), showNormal(), isVisible(), polish()

Reimplementado de QWidget.

Reimplementado en MenuBarEditor.

QSize QMenuBar::sizeHint ( ) const [virtual]

Reimplementado de QFrame.

Reimplementado en MenuBarEditor.

QSize QMenuBar::sizeHint ( ) const [virtual]

Reimplementado de QFrame.

Reimplementado en MenuBarEditor.

void QMenuBar::styleChange ( QStyle old) [protected, virtual]

Reimplementado de QFrame.

void QMenuBar::styleChange ( QStyle old) [protected, virtual]

Reimplementado de QFrame.

void QMenuBar::updateItem ( int  id) [virtual]

Virtual function; notifies subclasses about an item with id that has been changed.

Reimplementado de QMenuData.

void QMenuBar::updateItem ( int  id) [virtual]

Virtual function; notifies subclasses about an item with id that has been changed.

Reimplementado de QMenuData.


Documentación de las funciones relacionadas y clases amigas

QPopupMenu [friend]

Reimplementado de QMenuData.


Documentación de propiedades

bool QMenuBar::defaultUp [read, write]

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.

Separator QMenuBar::separator [read, write]

in which cases a menubar sparator is drawn


La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'