Qt Toolkit - QPopupMenu Class

# QPopupMenu Class Reference

The QPopupMenu class provides a popup menu widget. More...

`#include <qpopupmenu.h>`

Inherits QMenuData and QTableView.

List of all member functions.

## Public Members

- QPopupMenu ( QWidget * parent=0, const char * name=0 )
- ~QPopupMenu ()
- void popup ( const QPoint & pos, int indexAtPoint = 0 )
- virtual void updateItem ( int id )
- void setCheckable ( bool )
- bool isCheckable () const
- virtual void setFont ( const QFont & )
- virtual void show ()
- virtual void hide ()
- int exec ()
- int exec ( const QPoint & pos, int indexAtPoint = 0 )
- void setActiveItem ( int )
- int idAt ( int index ) const
- int idAt ( const QPoint & pos ) const

## Signals

- void activated ( int itemId )
- void highlighted ( int itemId )
- void activatedRedirect ( int itemId )
- void highlightedRedirect ( int itemId )
- void aboutToShow ()

## Protected Members

- virtual int cellHeight ( int )
- virtual int cellWidth ( int )
- virtual void paintCell ( QPainter *, int, int )
- virtual void paintEvent ( QPaintEvent * )
- virtual void mousePressEvent ( QMouseEvent * )
- virtual void mouseReleaseEvent ( QMouseEvent * )
- virtual void mouseMoveEvent ( QMouseEvent * )
- virtual void keyPressEvent ( QKeyEvent * )
- virtual void timerEvent ( QTimerEvent * )

## Detailed Description

The QPopupMenu class provides a popup menu widget.

The popup widget is different from other widgets in the way it relates to the parent widget.

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

See also: QMenuBar and GUI Design Handbook: Menu, Drop-Down and Pop-Up

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

## Member Function Documentation

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

Constructs a popup menu with a null parent and a widget name.

A popup menu must be a top level widget, i.e. parent must be 0. This argument is present merely for API uniformity.

### QPopupMenu::~QPopupMenu ()

Destroys the popup menu.

### void QPopupMenu::aboutToShow () `[signal]`

This signal is emited 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).

See also: setItemEnabled(), setItemChecked(), insertItem() and removeItem().

### 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 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 QPopupMenu::activatedRedirect ( int id ) `[signal]`

For internal use only.

### int QPopupMenu::cellHeight ( int row ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QTableView.

### int QPopupMenu::cellWidth ( int col ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QTableView.

### int QPopupMenu::exec ()

Execute this popup synchronously.

Similar to the above function, but the position of the popup is not set, so you must choose an appropriate position. The function move the popup if it is partially off-screen.

More common usage is to position the popup at the current mouse position:

          exec(QCursor::pos());

or aligned to a widget:

          exec(somewidget.mapToGlobal(QPoint(0,0)));

### int QPopupMenu::exec ( const QPoint & pos, int indexAtPoint = 0 )

Execute 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, or -1 if no item is selected (normally because the user presses Escape).

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:

          exec(somewidget.mapToGlobal(QPoint(0,0)));

See also: popup().

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

Reimplements QWidget::hide() for internal purposes.

Reimplemented from 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.

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 QPopupMenu::highlightedRedirect ( int id ) `[signal]`

For internal use only.

### int QPopupMenu::idAt ( const QPoint & pos ) const

Returns the identifier of the menu item at position index in the internal list, or -1 if index is out of range.

See also: QMenuData::setId() and QMenuData::indexOf().

### bool QPopupMenu::isCheckable () const

Returns whether display of check marks by the menu items is enabled.

See also: setCheckable() and QMenuData::setItemChecked().

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

Handles key press events for the popup menu.

Reimplemented from QWidget.

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

Handles mouse move events for the popup menu.

Reimplemented from QWidget.

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

Handles mouse press events for the popup menu.

Reimplemented from QWidget.

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

Handles mouse release events for the popup menu.

Reimplemented from QWidget.

### void QPopupMenu::paintCell ( QPainter * p, int row, int col ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QTableView.

### void QPopupMenu::paintEvent ( QPaintEvent * e ) `[virtual protected]`

Handles paint events for the popup menu.

Reimplemented from QWidget.

### void QPopupMenu::popup ( const QPoint & pos, int indexAtPoint = 0 )

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

Examples: qtimage/qtimage.cpp

### void QPopupMenu::setActiveItem ( int i )

Sets the currently active item to i and repaints as necessary.

### void QPopupMenu::setCheckable ( bool enable )

Enables or disables display of check marks by the menu items.

Notice that checking is always enabled when in windows-style.

See also: isCheckable() and QMenuData::setItemChecked().

Examples: grapher/grapher.cpp progress/progress.cpp

### void QPopupMenu::setFont ( const QFont & font ) `[virtual]`

Reimplements QWidget::setFont() to be able to refresh the popup menu when its font changes.

Reimplemented from QWidget.

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

Reimplements QWidget::show() for internal purposes.

Reimplemented from QWidget.

### void QPopupMenu::timerEvent ( QTimerEvent * e ) `[virtual protected]`

Handles timer events for the popup menu.

Reimplemented from QObject.

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:

- qpopupmenu.h: 1999/01/25
- qpopupmenu.cpp: 1999/01/26