Eneboo - Documentación para desarrolladores
|
The QMenuBar class provides a horizontal menu bar. Más...
#include <qmenubar.h>
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().
enum QMenuBar::Separator |
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.
enum QMenuBar::Separator |
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 | ( | ) |
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.
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::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.
Reimplementado de QFrame.
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.
Reimplementado de QObject.
Reimplementado en MenuBarEditor.
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.
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.
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.
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.
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.
Reimplementado de QWidget.
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.
Reimplementado de QWidget.
Reimplementado en MenuBarEditor.
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.
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.
void QMenuBar::highlighted | ( | int | itemId | ) | [signal] |
bool QMenuBar::isDefaultUp | ( | ) | const |
bool QMenuBar::isDefaultUp | ( | ) | const |
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.
Reimplementado de QWidget.
Reimplementado en MenuBarEditor.
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.
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] |
void QMenuBar::menuStateChanged | ( | ) | [protected, virtual] |
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.
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.
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.
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().
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::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.
QPopupMenu [friend] |
Reimplementado de QMenuData.
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