Qt logo

QPopupMenu Class Reference


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

#include <qpopupmenu.h>

Inherits QFrame and QMenuData.

List of all member functions.

Public Members

Signals

Protected Members


Detailed Description

The QPopupMenu class provides a popup menu 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 mainlyQt/editor.cpp layout/layout.cpp menu/menu.cpp progress/progress.cpp scrollview/scrollview.cpp


Member Function Documentation

QPopupMenu::QPopupMenu(QWidget*parent=0, constchar*name=0)

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

Although a popup menu is always a top level widget, if a parent is passed, the popup menu will be deleted on destruction of that parent (as with any other QObject).

QPopupMenu::~QPopupMenu()

Destroys the popup menu.

voidQPopupMenu::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).

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

voidQPopupMenu::activated(intid) [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().

voidQPopupMenu::activatedRedirect(intid) [signal]

For internal use only.

voidQPopupMenu::closeEvent(QCloseEvent*e) [virtualprotected]

Handles close events for the popup menu.

Reimplemented from QWidget.

boolQPopupMenu::customWhatsThis()const [virtual]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

intQPopupMenu::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)));

intQPopupMenu::exec(constQPoint&pos, intindexAtPoint=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 in either the popup menu or one of its submenus, 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)));

When positioning a popup with exec() or popup(), keep in mind that you cannot rely on the popup menu's current size(). For performance reasons, the popup adapts its size only when actually needed. 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.

See also: popup() and sizeHint().

voidQPopupMenu::hide() [virtual]

Reimplements QWidget::hide() for internal purposes.

Reimplemented from QWidget.

voidQPopupMenu::highlighted(intid) [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().

voidQPopupMenu::highlightedRedirect(intid) [signal]

For internal use only.

intQPopupMenu::idAt(constQPoint&pos)const

Return the id of the item at pos, or -1 if there is no item there, or if it is a separator item.

intQPopupMenu::idAt(intindex)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().

Examples: scrollview/scrollview.cpp

boolQPopupMenu::isCheckable()const

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

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

intQPopupMenu::itemHeight(QMenuItem*mi)const [protected]

Calculates the height in pixels of the item mi.

intQPopupMenu::itemHeight(introw)const [protected]

Calculates the height in pixels of the item in row row.

voidQPopupMenu::keyPressEvent(QKeyEvent*e) [virtualprotected]

Handles key press events for the popup menu.

Reimplemented from QWidget.

voidQPopupMenu::mouseMoveEvent(QMouseEvent*e) [virtualprotected]

Handles mouse move events for the popup menu.

Reimplemented from QWidget.

voidQPopupMenu::mousePressEvent(QMouseEvent*e) [virtualprotected]

Handles mouse press events for the popup menu.

Reimplemented from QWidget.

voidQPopupMenu::mouseReleaseEvent(QMouseEvent*e) [virtualprotected]

Handles mouse release events for the popup menu.

Reimplemented from QWidget.

voidQPopupMenu::paintEvent(QPaintEvent*e) [virtualprotected]

Handles paint events for the popup menu.

Reimplemented from QWidget.

voidQPopupMenu::popup(constQPoint&pos, intindexAtPoint=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().

When positioning a popup with exec() or popup(), keep in mind that you cannot rely on the popup menu's current size(). For performance reasons, the popup adapts its size only when actually needed. 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.

Examples: qtimage/qtimage.cpp

voidQPopupMenu::setActiveItem(inti) [virtual]

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

voidQPopupMenu::setCheckable(boolenable) [virtual]

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 menu/menu.cpp progress/progress.cpp scrollview/scrollview.cpp

voidQPopupMenu::setFont(constQFont&font) [virtual]

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

Reimplemented from QWidget.

voidQPopupMenu::show() [virtual]

Reimplements QWidget::show() for internal purposes.

Reimplemented from QWidget.

QSizeQPopupMenu::sizeHint()const [virtual]

Returns the size the popupmenu would use shall it become visible now. (##### is that english??)

Note that this size may be different from the popup's actual size. It changes all the time a new item is added or an existing one is modified. For performance reasons, QPopupMenu doesn't change its physical size each time this happens but only once before it is shown.

See also: exec() and show().

Reimplemented from QWidget.

voidQPopupMenu::styleChange(QStyle&old) [virtualprotected]

Reimplemented for internal purposes.

Reimplemented from QWidget.

voidQPopupMenu::timerEvent(QTimerEvent*e) [virtualprotected]

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.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2