Eneboo - Documentación para desarrolladores
|
The QPopupMenu class provides a popup menu widget. Más...
#include <qpopupmenu.h>
The QPopupMenu class provides a popup menu widget.
A popup menu widget is a selection menu. It can be either a pull-down menu in a menu bar or a standalone context (popup) menu. Pull-down menus are shown by the menu bar when the user clicks on the respective item or presses the specified shortcut key. Use QMenuBar::insertItem() to insert a popup menu into a menu bar. Show a context menu either asynchronously with popup() or synchronously with exec().
Technically, a popup menu consists of a list of menu items. You add items with insertItem(). An item is either a string, a pixmap or a custom item that provides its own drawing function (see QCustomMenuItem). In addition, items can have an optional icon drawn on the very left side and an accelerator key such as "Ctrl+X".
There are three kinds of menu items: separators, menu items that perform an action and menu items that show a submenu. Separators are inserted with insertSeparator(). For submenus, you pass a pointer to a QPopupMenu in your call to insertItem(). All other items are considered action items.
When inserting action items you usually specify a receiver and a slot. The receiver will be notifed whenever the item is selected. In addition, QPopupMenu provides two signals, activated() and highlighted(), which signal the identifier of the respective menu item. It is sometimes practical to connect several items to one slot. To distinguish between them, specify a slot that takes an integer argument and use setItemParameter() to associate a unique value with each item.
You clear a popup menu with clear() and remove single items with removeItem() or removeItemAt().
A popup menu can display check marks for certain items when enabled with setCheckable(TRUE). You check or uncheck items with setItemChecked().
Items are either enabled or disabled. You toggle their state with setItemEnabled(). Just before a popup menu becomes visible, it emits the aboutToShow() signal. You can use this signal to set the correct enabled/disabled states of all menu items before the user sees it. The corresponding aboutToHide() signal is emitted when the menu hides again.
You can provide What's This? help for single menu items with setWhatsThis(). See QWhatsThis for general information about this kind of lightweight online help.
For ultimate flexibility, you can also add entire widgets as items into a popup menu (for example, a color selector).
A QPopupMenu can also provide a tear-off menu. A tear-off menu is a top-level window that contains a copy of the menu. This makes it possible for the user to "tear off" frequently used menus and position them in a convenient place on the screen. If you want that functionality for a certain menu, insert a tear-off handle with insertTearOffHandle(). When using tear-off menus, bear in mind that the concept isn't typically used on Microsoft Windows so users may not be familiar with it. Consider using a QToolBar instead. Tear-off menus cannot contain custom widgets; if the original menu contains a custom widget item, this item is omitted.
menu/menu.cpp is an example of QMenuBar and QPopupMenu use.
insertItem removeItem removeItemAt clear text pixmap iconSet insertSeparator changeItem whatsThis setWhatsThis accel setAccel setItemEnabled isItemEnabled setItemVisible isItemVisible setItemChecked isItemChecked connectItem disconnectItem setItemParameter itemParameter
QPopupMenu::QPopupMenu | ( | QWidget * | parent = 0 , |
const char * | name = 0 |
||
) |
Constructs a popup menu called name with parent parent.
Although a popup menu is always a top-level widget, if a parent is passed the popup menu will be deleted when that parent is destroyed (as with any other QObject).
QPopupMenu::~QPopupMenu | ( | ) |
Destroys the popup menu.
QPopupMenu::QPopupMenu | ( | QWidget * | parent = 0 , |
const char * | name = 0 |
||
) |
QPopupMenu::~QPopupMenu | ( | ) |
void QPopupMenu::aboutToHide | ( | ) | [signal] |
This signal is emitted just before the popup menu is hidden after it has been displayed.
void QPopupMenu::aboutToHide | ( | ) | [signal] |
void QPopupMenu::aboutToShow | ( | ) | [signal] |
This signal is emitted just before the popup menu is displayed. You can connect it to any slot that sets up the menu contents (e.g. to ensure that the right items are enabled).
void QPopupMenu::aboutToShow | ( | ) | [signal] |
void QPopupMenu::activated | ( | int | id | ) | [signal] |
This signal is emitted when a menu item is selected; id is the id of the selected item.
Normally, you 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 QPopupMenu::activated | ( | int | itemId | ) | [signal] |
void QPopupMenu::activatedRedirect | ( | int | itemId | ) | [signal] |
void QPopupMenu::activatedRedirect | ( | int | itemId | ) | [signal] |
void QPopupMenu::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 QPopupMenu::closeEvent | ( | QCloseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive widget close events.
The default implementation calls e->accept(), which hides this widget. See the QCloseEvent documentation for more details.
Reimplementado de QWidget.
void QPopupMenu::closeEvent | ( | QCloseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
int QPopupMenu::columns | ( | ) | const [protected] |
If a popup menu does not fit on the screen it lays itself out so that it does fit. It is style dependent what layout means (for example, on Windows it will use multiple columns).
This functions returns the number of columns necessary.
int QPopupMenu::columns | ( | ) | const [protected] |
void QPopupMenu::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.
void QPopupMenu::drawContents | ( | QPainter * | p | ) | [protected, virtual] |
Draws all menu items using painter p.
Reimplementado de QFrame.
void QPopupMenu::drawItem | ( | QPainter * | p, |
int | tab, | ||
QMenuItem * | mi, | ||
bool | act, | ||
int | x, | ||
int | y, | ||
int | w, | ||
int | h | ||
) | [protected] |
void QPopupMenu::drawItem | ( | QPainter * | p, |
int | tab_, | ||
QMenuItem * | mi, | ||
bool | act, | ||
int | x, | ||
int | y, | ||
int | w, | ||
int | h | ||
) | [protected] |
Draws menu item mi in the area x, y, w, h, using painter p. The item is drawn active if act is TRUE or drawn inactive if act is FALSE. The rightmost tab_ pixels are used for accelerator text.
void QPopupMenu::enabledChange | ( | bool | oldEnabled | ) | [protected, virtual] |
This virtual function is called from setEnabled(). oldEnabled is the previous setting; you can get the new setting from isEnabled().
Reimplement this function if your widget needs to know when it becomes enabled or disabled. You will almost certainly need to update the widget using update().
The default implementation repaints the visible part of the widget.
Reimplementado de QWidget.
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Executes this popup synchronously.
Opens the popup menu so that the item number indexAtPoint will be at the specified global position pos. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
The return code is the id of the selected item in either the popup menu or one of its submenus, or -1 if no item is selected (normally because the user pressed Esc).
Note that all signals are emitted as usual. If you connect a menu item to a slot and call the menu's exec(), you get the result both via the signal-slot connection and in the return value of exec().
Common usage is to position the popup at the current mouse position:
exec( QCursor::pos() );
or aligned to a widget:
When positioning a popup with exec() or popup(), bear in mind that you cannot rely on the popup menu's current size(). For performance reasons, the popup adapts its size only when necessary. So in many cases, the size before and after the show is different. Instead, use sizeHint(). It calculates the proper size depending on the menu's current contents.
int QPopupMenu::exec | ( | ) |
int QPopupMenu::exec | ( | ) |
Executes this popup synchronously.
This is equivalent to {exec(mapToGlobal(QPoint(0,0)))}. In most situations you'll want to specify the position yourself, for example at the current mouse position:
exec(QCursor::pos());
or aligned to a widget:
void QPopupMenu::focusInEvent | ( | QFocusEvent * | ) | [protected, virtual] |
Reimplementado de QWidget.
void QPopupMenu::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.
Finds a new widget to give the keyboard focus to, as appropriate for Tab and Shift+Tab, and returns TRUE if is can find a new widget and FALSE if it can't,
If next is TRUE, this function searches "forwards", if next is FALSE, it searches "backwards".
Sometimes, you will want to reimplement this function. For example, a web browser might reimplement it to move its "current active link" forwards or backwards, and call QWidget::focusNextPrevChild() only when it reaches the last or first link on the "page".
Child widgets call focusNextPrevChild() on their parent widgets, but only the top-level widget decides where to redirect focus. By overriding this method for an object, you thus gain control of focus traversal for all child widgets.
Reimplementado de QWidget.
void QPopupMenu::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.
void QPopupMenu::focusOutEvent | ( | QFocusEvent * | ) | [protected, virtual] |
Reimplementado de QWidget.
void QPopupMenu::hide | ( | ) | [virtual] |
Reimplementado de QWidget.
void QPopupMenu::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 QPopupMenu::highlighted | ( | int | id | ) | [signal] |
This signal is emitted when a menu item is highlighted; id is the id of the highlighted item.
void QPopupMenu::highlighted | ( | int | itemId | ) | [signal] |
void QPopupMenu::highlightedRedirect | ( | int | itemId | ) | [signal] |
void QPopupMenu::highlightedRedirect | ( | int | itemId | ) | [signal] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Returns the id of the item at pos, or -1 if there is no item there or if it is a separator.
Returns the identifier of the menu item at position index in the internal list, or -1 if index is out of range.
Reimplementado de QMenuData.
Inserts a tear-off handle into the menu. A tear-off handle is a special menu item that creates a copy of the menu when the menu is selected. This "torn-off" copy lives in a separate window. It contains the same menu items as the original menu, with the exception of the tear-off handle.
The handle item is assigned the identifier id or an automatically generated identifier if id is < 0. The generated identifiers (negative integers) are guaranteed to be unique within the entire application.
The index specifies the position in the menu. The tear-off handle is appended at the end of the list if index is negative.
bool QPopupMenu::isCheckable | ( | ) | const |
bool QPopupMenu::isCheckable | ( | ) | const |
Calculates the height in pixels of the item in row row.
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Calculates the height in pixels of the menu item mi.
void QPopupMenu::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.
void QPopupMenu::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 QPopupMenu::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.
void QPopupMenu::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QPopupMenu::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QPopupMenu::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.
void QPopupMenu::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 QPopupMenu::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QPopupMenu::paintEvent | ( | QPaintEvent * | e | ) | [protected, virtual] |
Reimplementado de QFrame.
void QPopupMenu::paintEvent | ( | QPaintEvent * | event | ) | [protected, virtual] |
Processes the paint event event.
Paints the frame and the contents.
Opens the painter on the frame and calls drawFrame(), then drawContents().
Reimplementado de QFrame.
Displays the popup menu so that the item number indexAtPoint will be at the specified global position pos. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().
When positioning a popup with exec() or popup(), bear in mind that you cannot rely on the popup menu's current size(). For performance reasons, the popup adapts its size only when necessary, so in many cases, the size before and after the show is different. Instead, use sizeHint(). It calculates the proper size depending on the menu's current contents.
void QPopupMenu::setActiveItem | ( | int | i | ) | [virtual] |
Sets the currently active item to index i and repaints as necessary.
virtual void QPopupMenu::setActiveItem | ( | int | ) | [virtual] |
void QPopupMenu::setCheckable | ( | bool | enable | ) | [virtual] |
virtual void QPopupMenu::setCheckable | ( | bool | ) | [virtual] |
void QPopupMenu::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.
void QPopupMenu::show | ( | ) | [virtual] |
Reimplementado de QWidget.
void QPopupMenu::timerEvent | ( | QTimerEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive timer events for the object.
QTimer provides a higher-level interface to the timer functionality, and also more general information about timers.
Reimplementado de QObject.
void QPopupMenu::timerEvent | ( | QTimerEvent * | e | ) | [protected, virtual] |
Reimplementado de QObject.
void QPopupMenu::updateItem | ( | int | id | ) | [virtual] |
Virtual function; notifies subclasses about an item with id that has been changed.
Reimplementado de QMenuData.
void QPopupMenu::updateItem | ( | int | id | ) | [virtual] |
Updates the item with identity id.
Reimplementado de QMenuData.
QMenuData [friend] |
uint QPopupMenu::checkable [read, write] |
whether the display of check marks on menu items is enabled
When TRUE, the display of check marks on menu items is enabled. Checking is always enabled when in Windows-style.