QPopupMenu(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’– QPopupMenu πŸ’–

okay so this is the manual page for QPopupMenu, straight out of the Qt 3 docs (that's the 3qt manual, bestie, iykyk). It's a popup menu widget and it's genuinely iconic, so let's get into it. ✨


🌸 NAME 🌸

QPopupMenu β€” Popup menu widget. That's it, that's the whole vibe. πŸŽ€


✨ SYNOPSIS ✨

#include <qpopupmenu.h>

She Inherits QFrame and QMenuData. Two parents, one queen. πŸ‘‘

🫢 Public Members 🫢

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

πŸ¦‹ Signals πŸ¦‹

void activated ( int id )
void highlighted ( int id )
void aboutToShow ()
void aboutToHide ()

πŸ’œ Important Inherited Members πŸ’œ

These are the ones you'll actually be calling fr fr:

int insertItem ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )
int insertItem ( const QString & text, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, int id = -1, int index = -1 )
int insertItem ( const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QString & text, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, int id = -1, int index = -1 )
int insertItem ( const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, const QPixmap & pixmap, QPopupMenu * popup, int id = -1, int index = -1 )
int insertItem ( QWidget * widget, int id = -1, int index = -1 )
int insertItem ( const QIconSet & icon, QCustomMenuItem * custom, int id = -1, int index = -1 )
int insertItem ( QCustomMenuItem * custom, int id = -1, int index = -1 )
int insertSeparator ( int index = -1 )
void removeItem ( int id )
void removeItemAt ( int index )
void clear ()
QKeySequence accel ( int id ) const
void setAccel ( const QKeySequence & key, int id )
QIconSet * iconSet ( int id ) const
QString text ( int id ) const
QPixmap * pixmap ( int id ) const
void setWhatsThis ( int id, const QString & text )
QString whatsThis ( int id ) const
void changeItem ( int id, const QString & text )
void changeItem ( int id, const QPixmap & pixmap )
void changeItem ( int id, const QIconSet & icon, const QString & text )
void changeItem ( int id, const QIconSet & icon, const QPixmap & pixmap )
bool isItemEnabled ( int id ) const
void setItemEnabled ( int id, bool enable )
bool isItemChecked ( int id ) const
void setItemChecked ( int id, bool check )
bool isItemVisible ( int id ) const
void setItemVisible ( int id, bool visible )
bool connectItem ( int id, const QObject * receiver, const char * member )
bool disconnectItem ( int id, const QObject * receiver, const char * member )
bool setItemParameter ( int id, int param )
int itemParameter ( int id ) const

⭐ Properties ⭐

  • bool checkable β€” whether the display of check marks on menu items is enabled. Little checkmarks, the moment. βœ…

🌈 Protected Members 🌈

int itemHeight ( int row ) const
int itemHeight ( QMenuItem * mi ) const
void drawItem ( QPainter * p, int tab_, QMenuItem * mi, bool act, int x, int y, int w, int h )
virtual void drawContents ( QPainter * p )
int columns () const

πŸ’… DESCRIPTION πŸ’…

The QPopupMenu class provides a popup menu widget. slay

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".

not me noticing the quote placement in " Ctrl+X" β€” that's exactly how the original has it, keep it, don't touch it πŸ™ˆ

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.

⚠️ bestie, read that again: tear-off menus cannot contain custom widgets, and if your original menu has a custom widget item in it, that item gets omitted. No cap.

menu/menu.cpp is an example of QMenuBar and QPopupMenu use.

[Image Omitted]

[Image Omitted]

See also QMenuBar, GUI Design Handbook: Menu, Drop-Down and Pop-Up, Main Window and Related Classes, and Basic Widgets.


πŸ“– MEMBER FUNCTION DOCUMENTATION πŸ“–

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). So yes, it's top-level but it still gets taken out when parent goes. πŸ’€

QPopupMenu::~QPopupMenu ()

Destroys the popup menu. bye bestie πŸ¦‹

void QPopupMenu::aboutToHide () [signal]

This signal is emitted just before the popup menu is hidden after it has been displayed.

Warning: Do not open a widget in a slot connected to this signal. like literally do not, the original says don't, so don't πŸ™…β€β™€οΈ

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

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

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

Example: mdi/application.cpp.

QKeySequence QMenuData::accel ( int id ) const

Returns the accelerator key that has been defined for the menu item id, or 0 if it has no accelerator key or if there is no such menu item.

See also setAccel(), QAccel, and qnamespace.h.

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.

See also highlighted() and QMenuData::insertItem().

Examples:

void QMenuData::changeItem ( int id, const QString & text )

Changes the text of the menu item id to text. If the item has an icon, the icon remains unchanged.

See also text().

void QMenuData::changeItem ( int id, const QPixmap & pixmap )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Changes the pixmap of the menu item id to the pixmap pixmap. If the item has an icon, the icon is unchanged.

See also pixmap().

void QMenuData::changeItem ( int id, const QIconSet & icon, const QString & text )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Changes the iconset and text of the menu item id to the icon and text respectively.

See also pixmap().

void QMenuData::changeItem ( int id, const QIconSet & icon, const QPixmap & pixmap )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Changes the iconset and pixmap of the menu item id to icon and pixmap respectively.

See also pixmap().

void QMenuData::clear ()

Removes all menu items. poof, gone, no trace ✨

See also removeItem() and removeItemAt().

Examples:

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.

See also sizeHint.

πŸ’« bool QMenuData::connectItem ( int id, const QObject * receiver, const char * member )

Okay so bestie, this one hooks up the menu item with identifier id to receiver's member slot (or signal, she's flexible like that πŸ’…).

The receiver's slot (or signal) fires the moment that menu item gets activated. Iconic behavior, honestly.

See also disconnectItem() and setItemParameter().

Example: menu/menu.cpp.


🫢 bool QMenuData::disconnectItem ( int id, const QObject * receiver, const char * member )

Undoes the above. Detaches receiver's member from the menu item with identifier id.

Heads up: all connections get yeeted when the menu data object is destroyed. No lingering attachments, we love a clean breakup. 🧹

See also connectItem() and setItemParameter().


🎨 void QPopupMenu::drawContents ( QPainter * p ) [virtual protected]

Draws every single menu item using painter p. That's it, that's the function. The artiste does the work. ✨

Reimplemented from QFrame.


πŸ–ŒοΈ void QPopupMenu::drawItem ( QPainter * p, int tab_, QMenuItem * mi, bool act, int x, int y, int w, int h ) [protected]

Paints menu item mi inside the area x, y, w, h, using painter p. The item comes out active if act is TRUE and inactive if act is FALSE. The rightmost tab_ pixels are reserved for the accelerator text β€” that's its lil lane, don't crowd it. πŸ’…

See also QStyle::drawControl().


⚑ int QPopupMenu::exec ()

Runs this popup synchronously. Very main-character, she blocks until she's done.

This is literally equivalent to exec(mapToGlobal(QPoint(0,0))). But most of the time you're gonna wanna say where she goes yourself, like at the current mouse position:

exec(QCursor::pos());

or lined up with a widget:

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

Examples:


πŸ“ int QPopupMenu::exec ( const QPoint & pos, int indexAtPoint = 0 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Executes this popup synchronously. (Yes, again. Same energy. πŸ”₯)

She opens the popup menu so that item number indexAtPoint lands at the specified global position pos. Need to translate a widget's local coordinates into global ones? That's QWidget::mapToGlobal(), bestie.

The return code is the id of the selected item β€” either from the popup menu itself or from one of its submenus β€” or -1 if nothing got selected (usually because the user hit Esc. classic πŸ™ˆ).

Not me pointing out that all signals are emitted as usual. So if you connect a menu item to a slot and call the menu's exec(), you get the result twice β€” once through the signal-slot connection, and once in exec()'s return value. Double delivery, no cap.

Common usage is to park the popup at the current mouse position:

exec( QCursor::pos() );

or aligned to a widget:

exec( somewidget.mapToGlobal(QPoint(0, 0)) );
Real talk though: when you're positioning a popup with exec() or popup(), do not trust the popup menu's current size(). For performance reasons the popup only resizes itself when it actually has to, so the size before and after the show is gonna be different a lot of the time. Use sizeHint() instead β€” it works out the proper size based on the menu's current contents. πŸŽ€

See also popup() and sizeHint.


🌟 void QPopupMenu::highlighted ( int id ) [signal]

Fires when a menu item gets highlighted, and id is the id of the item that got the spotlight. Main character moment, obviously. πŸ‘‘

See also activated() and QMenuData::insertItem().


πŸ–ΌοΈ QIconSet * QMenuData::iconSet ( int id ) const

Hands back the icon set that's been set for menu item id, or 0 if no icon set has been set at all (she's got nothing on, leave her alone).

See also changeItem(), text(), and pixmap().


πŸ”’ int QPopupMenu::idAt ( int index ) const

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

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

Example: scrollview/scrollview.cpp.


πŸ“Œ int QPopupMenu::idAt ( const QPoint & pos ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the id of the item at pos, or -1 if there's no item there or if the thing at pos is a separator. Separators have no identity, they're just vibes. πŸ¦‹


πŸ› οΈ int QMenuData::insertItem ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )

Okay so the whole insertItem() family is how you add menu items into a popup menu or a menu bar. Big family. Lots of cousins. All valid. 🫢

A menu item is usually either a text string or a pixmap, both with an optional icon or keyboard accelerator. And for the special cases? You can also insert custom items (see QCustomMenuItem) or even full widgets into popup menus. Wild, I know.

Some insertItem() members take a popup menu as an additional argument β€” use that to insert submenus into existing menus, or pulldown menus into a menu bar.

The number of insert functions may look confusing, but they are actually quite simple to use. I promise. Trust. ✨

This default version inserts a menu item with the text text, the accelerator key accel, an id and an optional index, and connects it to the slot member in the object receiver.

Example:

QMenuBar   *mainMenu = new QMenuBar;
QPopupMenu *fileMenu = new QPopupMenu;
fileMenu->insertItem( "New",  myView, SLOT(newFile()), CTRL+Key_N );
fileMenu->insertItem( "Open", myView, SLOT(open()),    CTRL+Key_O );
mainMenu->insertItem( "File", fileMenu );

Not all insert functions take an object/slot parameter or an accelerator key. For those items, use connectItem() and setAccel().

If you need to translate accelerators, use tr() with the text and accelerator. (For translations use a string key sequence.):

fileMenu->insertItem( tr("Open"), myView, SLOT(open()),
                      tr("Ctrl+O") );

In the example above, pressing Ctrl+O or selecting "Open" from the menu activates the myView->open() function.

Some insert functions take a QIconSet parameter to specify the little menu item icon. Note that you can always pass a QPixmap object instead.

The id specifies the identification number associated with the menu item. Only positive values are valid, bestie β€” a negative value makes Qt pick a unique id for the item itself.

The index specifies the position in the menu. If index is negative, the menu item just gets appended at the end of the list. Whatever, she'll find a spot. πŸ’…

🧠 Lowkey important: keyboard accelerators in Qt are not application-global. They're bound to a certain top-level window instead. So for example, accelerators in QPopupMenu items only work for menus that are associated with a certain window. This holds true for popup menus that live in a menu bar, since their accelerators get installed in the menu bar itself. It also applies to stand-alone popup menus that have a top-level widget in their parentWidget() chain β€” the menu will then install its accelerator object on that top-level widget. For all other cases, use an independent QAccel object.
⚠️ Warning: Be careful when passing a literal 0 to insertItem() because some C++ compilers will choose the wrong overloaded function. Cast the 0 to what you actually mean, e.g. (QObject*)0.
⚠️ Warning: On Mac OS X, items that connect to a slot and are inserted into a menubar will not function, because we use the native menubar that knows nothing about signals or slots. Instead, insert the items into a popup menu and insert the popup menu into the menubar. This may be fixed in a future Qt version.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and qnamespace.h.

Examples:


🌈 int QMenuData::insertItem ( const QIconSet & icon, const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with icon icon, text text, accelerator accel, optional id id, and optional index position. The menu item gets connected to the receiver's member slot. The icon shows up to the left of the text in the item β€” its designated spot, we respect it. ✨

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and qnamespace.h.


πŸŽ€ int QMenuData::insertItem ( const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with pixmap pixmap, accelerator accel, optional id id, and optional index position. The menu item gets connected to the receiver's member slot. The icon shows up to the left of the text in the item.

To look best when being highlighted as a menu item, the pixmap should provide a mask (see QPixmap::mask()). Glow-up tip, free of charge. πŸ’…

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


πŸ¦‹ int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with icon icon, pixmap pixmap, accelerator accel, optional id id, and optional index position. The icon displays to the left of the pixmap in the item. The item is connected to the member slot in the receiver object.

Again: to look best when being highlighted as a menu item, the pixmap should provide a mask (see QPixmap::mask()).

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), connectItem(), QAccel, and qnamespace.h.


πŸ’– int QMenuData::insertItem ( const QString & text, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with text text, optional id id, and optional index position. No receiver, no slot, no drama β€” just a label chilling in a menu. πŸ“

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


⭐ int QMenuData::insertItem ( const QIconSet & icon, const QString & text, int id = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a menu item with icon icon, text text, optional id id, and optional index position. The icon shows up to the left of the text in the item, right where it belongs.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().

int QMenuData::insertItem ( const QString & text, QPopupMenu * popup, int id =
       -1, int index = -1 )

okay so this one is another overloaded member function, provided for convenience, and it behaves essentially like the one above it πŸ’–.

You're inserting a menu item with text text, a submenu popup, an optional id id, and an optional index position index.

⚠️ bestie listen β€” the popup must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed, and it is not deleted when the menu is deleted. So don't just forget about it, ok?? 🫢

Returns the allocated menu identifier number (that's id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


int QMenuData::insertItem ( const QIconSet & icon, const QString & text,
       QPopupMenu * popup, int id = -1, int index = -1 )

Another overloaded member function, provided for convenience, behaving essentially like the above function ✨.

Inserts a menu item with icon icon, text text, submenu popup, optional id id, and optional index position index. The icon gets displayed to the left of the text in the item. it's giving little picture, little words, so cute 🌸

⚠️ same deal, no cap: the popup must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


int QMenuData::insertItem ( const QPixmap & pixmap, int id = -1, int index = -1
       )

Overloaded member function, provided for convenience, behaves essentially like the above function πŸ’….

Inserts a menu item with pixmap pixmap, optional id id, and optional index position index.

To look best when being highlighted as a menu item, the pixmap should provide a mask β€” see QPixmap::mask(). (lowkey it just wants to look good highlighted, relatable πŸŽ€)

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, int
       id = -1, int index = -1 )

Overloaded member function, provided for convenience, behaves essentially like the above function ⭐.

Inserts a menu item with icon icon, pixmap pixmap, optional id id, and optional index position index. The icon is displayed to the left of the pixmap in the item.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


int QMenuData::insertItem ( const QPixmap & pixmap, QPopupMenu * popup, int id
       = -1, int index = -1 )

Overloaded member function, provided for convenience, behaves essentially like the above function πŸ¦‹.

Inserts a menu item with pixmap pixmap, submenu popup, optional id id, and optional index position index.

⚠️ yup, again: the popup must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap,
       QPopupMenu * popup, int id = -1, int index = -1 )

Overloaded member function, provided for convenience, behaves essentially like the above function πŸ”₯.

Inserts a menu item with icon icon, pixmap pixmap, submenu popup, optional id id, and optional index position index. The icon is displayed to the left of the pixmap in the item. (icon + pixmap + submenu?? the whole buffet, we love a maximalist moment πŸ’œ)

⚠️ one more time for the people in the back: the popup must be deleted by the programmer or by its parent widget. It is not deleted when this menu item is removed or when the menu is deleted.

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem(), changeItem(), setAccel(), and connectItem().


int QMenuData::insertItem ( QWidget * widget, int id = -1, int index = -1 )

Overloaded member function, provided for convenience, behaves essentially like the above function πŸ‘‘

Inserts a menu item that consists of the widget widget, with optional id id, and optional index position index.

Ownership of widget is transferred to the popup menu or to the menu bar. (so it's yours no more, it's the menu's now, periodt πŸ’…)

Theoretically, any widget can be inserted into a popup menu. In practice, this only makes sense with certain widgets. ngl that's such a shady sentence and yet so true 😭

If a widget is not focus-enabled (see QWidget::isFocusEnabled()), the menu treats it as a separator β€” which means the item is not selectable and will never get focus. So in this way you can, for example, simply insert a QLabel if you need a popup menu with a title. cute, iconic, no interaction required πŸŽ€

If the widget is focus-enabled it will get focus when the user traverses the popup menu with the arrow keys. If the widget does not accept ArrowUp and ArrowDown in its key event handler, the focus will move back to the menu when the respective arrow key is hit one more time. This works with a QLineEdit, for example. If the widget accepts the arrow key itself, it must also provide the possibility to put the focus back on the menu again by calling QWidget::focusNextPrevChild(). Also β€” if the embedded widget closes the menu when the user made a selection, this can be done safely by calling:

if ( isVisible() &&
     parentWidget() &&
     parentWidget()->inherits("QPopupMenu") )
    parentWidget()->close();

Returns the allocated menu identifier number (id if id >= 0).

See also removeItem().


int QMenuData::insertItem ( const QIconSet & icon, QCustomMenuItem * custom,
       int id = -1, int index = -1 )

Overloaded member function, provided for convenience, behaves essentially like the above function ✨.

Inserts a custom menu item custom with an icon and with optional id id, and optional index position index.

This only works with popup menus. It is not supported for menu bars. Ownership of custom is transferred to the popup menu.

If you want to connect a custom item to a slot, use connectItem().

Returns the allocated menu identifier number (id if id >= 0).

See also connectItem(), removeItem(), and QCustomMenuItem.


int QMenuData::insertItem ( QCustomMenuItem * custom, int id = -1, int index =
       -1 )

Overloaded member function, provided for convenience, behaves essentially like the above function 🌈.

Inserts a custom menu item custom with optional id id, and optional index position index.

This only works with popup menus. It is not supported for menu bars. Ownership of custom is transferred to the popup menu.

If you want to connect a custom item to a slot, use connectItem().

Returns the allocated menu identifier number (id if id >= 0).

See also connectItem(), removeItem(), and QCustomMenuItem.


int QMenuData::insertSeparator ( int index = -1 )

Inserts a separator at position index, and returns the menu identifier number allocated to it. The separator becomes the last menu item if index is negative. (the humble little line divider, the unsung hero of menus 🫢)

In a popup menu a separator is rendered as a horizontal line. In a Motif menu bar a separator is spacing, so the rest of the items (normally just "Help") are drawn right-justified. In a Windows menu bar separators are ignored β€” to comply with the Windows style guidelines.

Examples:


int QPopupMenu::insertTearOffHandle ( int id = -1, int index = -1 )

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. no cap, unique across the whole app πŸ’―

The index specifies the position in the menu. The tear-off handle is appended at the end of the list if index is negative.

Example: menu/menu.cpp.


bool QPopupMenu::isCheckable () const

Returns TRUE if the display of check marks on menu items is enabled; otherwise returns FALSE. See the "checkable" property for details. ✨


bool QMenuData::isItemChecked ( int id ) const

Returns TRUE if the menu item with the id id has been checked; otherwise returns FALSE.

See also setItemChecked().

Examples:


bool QMenuData::isItemEnabled ( int id ) const

Returns TRUE if the item with identifier id is enabled; otherwise returns FALSE πŸ’…

See also setItemEnabled() and isItemVisible().


bool QMenuData::isItemVisible ( int id ) const

Returns TRUE if the menu item with the id id is visible; otherwise returns FALSE.

See also setItemVisible(). πŸ‘€


int QPopupMenu::itemHeight ( int row ) const [protected]

Calculates the height in pixels of the item in row row. πŸ“


int QPopupMenu::itemHeight ( QMenuItem * mi ) const [protected]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Calculates the height in pixels of the menu item mi.


int QMenuData::itemParameter ( int id ) const

Returns the parameter of the activation signal of item id.

If no parameter has been specified for this item with setItemParameter(), the value defaults to id.

See also connectItem(), disconnectItem(), and setItemParameter().


QPixmap * QMenuData::pixmap ( int id ) const

Returns the pixmap that has been set for menu item id, or 0 if no pixmap has been set. (zero pixmap = the void, we've all been there 😭)

See also changeItem(), text(), and iconSet().


void QPopupMenu::popup ( const QPoint & pos, int indexAtPoint = -1 )

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.

πŸ’€ fr fr do not trust size() here. the size is a lie until it's not. use sizeHint() and save yourself.

Example: listviews/listviews.cpp.


void QMenuData::removeItem ( int id )

Removes the menu item that has the identifier id.

See also removeItemAt() and clear().

Example: chart/chartform.cpp.


void QMenuData::removeItemAt ( int index )

Removes the menu item at position index. 🧹

See also removeItem() and clear().

  • void QMenuData::setAccel ( const QKeySequence & key, int id ) β€” bestie, this one sets the accelerator key for the menu item id to key. ✨

An accelerator key is like, a key code PLUS a lil combo of modifiers β€” SHIFT, CTRL, ALT or UNICODE_ACCEL β€” all OR'ed or added together. The header file qnamespace.h has the whole list of key codes if you wanna go shopping. πŸ’…

When you define an accelerator key, some text gets added to the menu item β€” for example, CTRL + Key_O produces "Ctrl+O". And that text is formatted differently on different platforms, so don't come for it, it's just how it is. πŸŽ€

okay important thing, no cap: keyboard accelerators in Qt are not application-global. They're bound to a certain top-level window. So accelerators in QPopupMenu items only work for menus associated with a certain window. That's true for popup menus living in a menu bar, since their accelerators get installed in the menu bar itself. It also applies to stand-alone popup menus that have a top-level widget in their parentWidget() chain β€” the menu will install its accelerator object on that top-level widget. For all the other cases? Use an independent QAccel object. periodt. πŸ™ˆ

Example, and I'm keeping this exactly as written because it ate:

QMenuBar *mainMenu = new QMenuBar;
QPopupMenu *fileMenu = new QPopupMenu;       // file sub menu
fileMenu->insertItem( "Open Document", 67 ); // add "Open" item
fileMenu->setAccel( CTRL + Key_O, 67 );      // Ctrl+O to open
fileMenu->insertItem( "Quit", 69 );          // add "Quit" item
fileMenu->setAccel( CTRL + ALT + Key_Delete, 69 ); // add Alt+Del to quit
mainMenu->insertItem( "File", fileMenu );    // add the file menu

If you need to translate accelerators, use tr() with a string, like:

fileMenu->setAccel( tr("Ctrl+O"), 67 );

You can also specify the accelerator right in the insertItem() function. Or honestly you may prefer to use QAction to associate accelerators with menu items. slay. πŸ’–

See also accel(), insertItem(), QAccel, and QAction.

Example: menu/menu.cpp.

  • void QPopupMenu::setActiveItem ( int i ) [virtual] β€” sets the currently active item to index i and repaints as necessary. that's it, that's the whole vibe. ✨
  • void QPopupMenu::setCheckable ( bool ) [virtual] β€” sets whether the display of check marks on menu items is enabled. See the "checkable" property for the deets. πŸ’…
  • void QMenuData::setItemChecked ( int id, bool check ) β€” if check is TRUE, it checks the menu item with id id; otherwise it unchecks the menu item with id id. And it calls QPopupMenu::setCheckable( TRUE ) if necessary. 🫢

See also isItemChecked().

Examples:

  • void QMenuData::setItemEnabled ( int id, bool enable ) β€” if enable is TRUE, enables the menu item with identifier id; otherwise disables the menu item with identifier id. iconic behavior tbh. πŸ‘‘

See also isItemEnabled().

Examples:

  • bool QMenuData::setItemParameter ( int id, int param ) β€” sets the parameter of the activation signal of item id to param. πŸŽ€

If any receiver takes an integer parameter, this value is what gets passed.

See also connectItem(), disconnectItem(), and itemParameter().

Example: mdi/application.cpp.

  • void QMenuData::setItemVisible ( int id, bool visible ) β€” if visible is TRUE, shows the menu item with id id; otherwise hides the menu item with id id. peekaboo πŸ¦‹

See also isItemVisible() and isItemEnabled().

  • void QMenuData::setWhatsThis ( int id, const QString & text ) β€” sets text as What's This help for the menu item with identifier id. So helpful. 🌸

See also whatsThis().

Examples:

  • QString QMenuData::text ( int id ) const β€” returns the text that has been set for menu item id, or QString::null if no text has been set. no text, no problem. πŸ’œ

See also changeItem(), pixmap(), and iconSet().

Examples:

  • void QPopupMenu::updateItem ( int id ) [virtual] β€” updates the item with identity id. πŸ”₯

Reimplemented from QMenuData.

  • QString QMenuData::whatsThis ( int id ) const β€” returns the What's This help text for the item with identifier id, or QString::null if no text has yet been defined. 😭

See also setWhatsThis().


πŸŽ€ PROPERTY DOCUMENTATION πŸŽ€

🌟 bool checkable 🌟

This property holds whether the display of check marks on menu items is enabled.

When TRUE, the display of check marks on menu items is enabled. And lowkey important: checking is always enabled when in Windows-style. πŸͺŸβœ¨

See also QMenuData::setItemChecked().

Set this property's value with setCheckable() and get this property's value with isCheckable().


πŸ‘€ SEE ALSO πŸ‘€


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


✨ AUTHOR ✨

Generated automatically from the source code. (not me writing a whole essay, the machine did that πŸ™ˆ)


πŸ’€ BUGS πŸ’€

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. 🫢

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qpopupmenu.3qt) and the Qt version (3.3.8).


okay bestie that's the whole page!! πŸŽ€ this one came from the Trolltech AS girlies, dated 2 February 2007, and it's the QPopupMenu(3qt) page β€” go forth and make the prettiest menus, mwah πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from