QMenuData(3qt)
πΈ QMenuData π
(that's the QMenuData(3qt) manual page, bestie β Qt's whole menu blueprint situation)
β¨ NAME β¨
QMenuData β the base class for QMenuBar and QPopupMenu. Yeah, it's the momager of menus. π
π SYNOPSIS π
#include <qmenudata.h>
Inherited by QMenuBar and QPopupMenu. So they're the nepo babies, but like, in a cute way. π«Ά
π Public Members
QMenuData ()
virtual ~QMenuData ()
uint count () const
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
)
void changeItem ( const QString & text, int id ) (obsolete)
void changeItem ( const QPixmap & pixmap, int id ) (obsolete)
void changeItem ( const QIconSet & icon, const QString & text, int id )
(obsolete)
bool isItemActive ( int id ) const
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 )
virtual void updateItem ( int id )
int indexOf ( int id ) const
int idAt ( int index ) const
virtual void setId ( int index, int id )
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
QMenuItem * findItem ( int id ) const
QMenuItem * findItem ( int id, QMenuData ** parent ) const
virtual void activateItemAt ( int index )
π¦ Protected Members
virtual void menuContentsChanged ()
virtual void menuStateChanged ()
virtual void menuInsPopup ( QPopupMenu * )
virtual void menuDelPopup ( QPopupMenu * )
π DESCRIPTION π
Okay so. The QMenuData class is a base class for QMenuBar and QPopupMenu. It's giving "foundation", it's giving "everything you see in a menu is living in here".
QMenuData has an internal list of menu items. And bestie, a menu item can have text(), an accelerator, a pixmap(), an iconSet(), a whatsThis() text and a popup menu (unless it is a separator, obviously β separators are the little line breaks of the menu world, no notes π«). Menu items may optionally be checked (except for separators, again, they simply do not have that range).
The menu item sends out an activated() signal when it is chosen and a highlighted() signal when it receives the user input focus. So it's literally announcing its own main character moments. π
Menu items are assigned the menu identifier id that is passed in insertItem() or an automatically generated identifier if id is < 0 (the default). The generated identifiers (negative integers) are guaranteed to be unique within the entire application. The identifier is used to access the menu item in other functions. So yes, every single item has its own little government name. πͺͺ
Menu items can be removed with removeItem() and removeItemAt(), or changed with changeItem(). All menu items can be removed with clear(). Accelerators can be changed or set with setAccel(). Checkable items can be checked or unchecked with setItemChecked(). Items can be enabled or disabled using setItemEnabled() and connected and disconnected with connectItem() and disconnectItem() respectively. By default, newly created menu items are visible. They can be hidden (and shown again) with setItemVisible(). It's giving glow-up AND glow-down, both available. β¨
Menu items are stored in a list. Use findItem() to find an item by its list position or by its menu identifier. (See also indexOf() and idAt().)
See also QAccel, QPopupMenu, QAction, and Miscellaneous Classes.
π MEMBER FUNCTION DOCUMENTATION π
πΈ QMenuData::QMenuData ()
Constructs an empty menu data list. Blank slate, no thoughts, just vibes. π«§
π QMenuData::~QMenuData () [virtual]
Removes all menu items and disconnects any signals that have been connected. It's the farewell tour, and she's taking everything with her. π
π 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 QMenuData::activateItemAt ( int index ) [virtual]
Activates the menu item at position index.
If the index is invalid (for example, -1), the object itself is deactivated. So no item, no activation β the object just logs off. π
π¦ 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. Glow-up for the words only, the icon is staying exactly as she is. π
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. Two-for-one makeover, we love to see it. β¨
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::changeItem ( const QString & text, int id )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Changes the text of the menu item id. If the item has an icon, the icon remains unchanged.
See also text().
π void QMenuData::changeItem ( const QPixmap & pixmap, int id )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Changes the pixmap of the menu item id. If the item has an icon, the icon remains unchanged.
See also pixmap().
π void QMenuData::changeItem ( const QIconSet & icon, const QString & text, int id )
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Changes the icon and text of the menu item id.
See also pixmap().
π«§ void QMenuData::clear ()
Removes all menu items. Full reset, no survivors, the menu is a clean slate. π§Ό
See also removeItem() and removeItemAt().
Examples:
(yes bestie, the examples list is genuinely just sitting there empty in the original β not me leaving things out, I promise π«Ά)
π₯ bool QMenuData::connectItem ( int id, const QObject * receiver, const char * member )
Connects the menu item with identifier id to receiver's member slot or signal.
The receiver's slot (or signal) is activated when the menu item is activated. So it's giving "you click, she responds". π
See also disconnectItem() and setItemParameter().
Example: menu/menu.cpp.
πΈ uint QMenuData::count () const
Returns the number of items in the menu. Headcount, bestie. π’
π bool QMenuData::disconnectItem ( int id, const QObject * receiver, const char * member )
Disconnects the receiver's member from the menu item with identifier id.
All connections are removed when the menu data object is destroyed. (She takes the whole contact list with her, iconic behaviour.) π
See also connectItem() and setItemParameter().
β QMenuItem * QMenuData::findItem ( int id ) const
Returns the menu item with identifier id, or 0 if there is no item with this identifier.
Note that QMenuItem is an internal class, and that you should not need to call this function. Use the higher level functions like text(), pixmap() and changeItem() to get and modify menu item attributes instead. Like, that's the whole point, bestie β stay out of the backend. π
See also indexOf().
Example: chart/chartform.cpp.
π¦ QMenuItem * QMenuData::findItem ( int id, QMenuData ** parent ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns the menu item with identifier id, or 0 if there is no item with this identifier. Changes *parent to point to the parent of the return value. So she finds the item AND snitches on where it lives. π΅οΈβοΈ
Note that QMenuItem is an internal class, and that you should not need to call this function. Use the higher level functions like text(), pixmap() and changeItem() to get and modify menu item attributes instead.
See also indexOf().
π QIconSet * QMenuData::iconSet ( int id ) const
Returns the icon set that has been set for menu item id, or 0 if no icon set has been set.
See also changeItem(), text(), and pixmap().
π int QMenuData::idAt ( int index ) const
Returns the identifier of the menu item at position index in the internal list, or -1 if index is out of range. If you're reaching for a spot that doesn't exist, she's handing you -1 and walking away. π
See also setId() and indexOf().
π int QMenuData::indexOf ( int id ) const
Returns the index of the menu item with identifier id, or -1 if there is no item with this identifier. Same energy, opposite direction β id in, position out. π
See also idAt() and findItem().
Example: scrollview/scrollview.cpp.
πΈ int QMenuData::insertItem ( const QString & text, const QObject * receiver, const char * member, const QKeySequence & accel = 0, int id = -1, int index = -1 ) πΈ
okay bestie so the whole insertItem() family is the way you β¨add stuffβ¨ into a popup menu or a menu bar. it's giving menu-decorating era π
A menu item is usually either a text string or a pixmap, and both of those can carry an optional icon or keyboard accelerator. for the β¨specialβ¨ cases you can also insert custom items (peep QCustomMenuItem) or even literally widgets into popup menus. icon behavior fr fr.
Some insertItem() members take a popup menu as an extra argument. use that to insert submenus into existing menus, or pulldown menus into a menu bar. so handy π«Ά
ngl the number of insert functions may look confusing, but they are actually quite simple to use. i promise. stay with me π
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() instead.
If you need to translate accelerators, use tr() with the text and accelerator. (for translations use a string key sequence.) like so:
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. iconic behavior β¨
Some insert functions take a QIconSet parameter to specify the little menu item icon. note that you can always pass a QPixmap object instead. whatever vibes.
The id specifies the identification number associated with the menu item. Note that only positive values are valid, as a negative value will make Qt select a unique id for the item.
The index specifies the position in the menu. the menu item is appended at the end of the list if index is negative.
Note that keyboard accelerators in Qt are not application-global β instead they are bound to a certain top-level window. for example, accelerators in QPopupMenu items only work for menus that are associated with a certain window. this is true for popup menus that live in a menu bar since their accelerators will then be installed in the menu bar itself. this 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 literal0toinsertItem()because some C++ compilers choose the wrong overloaded function. Cast the0to what you mean, e.g.(QObject*)0. no cap, this one bites people.
β οΈ Warning: On Mac OS X, items that connect to a slot that are inserted into a menubar will not function as 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. (they're all besties like that π«Ά)
Inserts a menu item with icon icon, text text, accelerator accel, optional id id, and optional index position. The menu item is connected it to the receiver's member slot. The icon will be displayed to the left of the text in the item.
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 is connected it to the receiver's member slot. The icon will be displayed 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 requirement honestly β¨
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 will be displayed to the left of the pixmap in the item. The item is connected to the member slot in the receiver object.
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.
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 will be displayed to the left of the text in the item.
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 ) π
This is an overloaded member function, provided for convenience. it behaves essentially like the above function.
Inserts a menu item with text text, submenu popup, optional id id, and optional index position.
π 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. so don't forget it, bestie.
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, QPopupMenu * popup, 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, submenu popup, optional id id, and optional index position. The icon will be displayed to the left of the text in the item.
π 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 ) π
This is an overloaded member function, provided for convenience. it behaves essentially like the above function.
Inserts a menu item with pixmap pixmap, optional id id, and optional index position.
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(), and connectItem().
π
int QMenuData::insertItem ( const QIconSet & icon, const QPixmap & pixmap, 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, optional id id, and optional index position. The icon will be 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 ) π§
This is an overloaded member function, provided for convenience. it behaves essentially like the above function.
Inserts a menu item with pixmap pixmap, submenu popup, optional id id, and optional index position.
π 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 ) β
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 submenu popup, optional id id, and optional index position. The icon will be displayed to the left of the pixmap in the item.
π 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 )
okay so this is one of those overloaded member function, provided for convenience situations β it behaves essentially like the above function, it's just vibing in a different font π
What it does: it slides a menu item into the menu that is literally just the widget widget, with the optional id id, at the optional index position. No notes.
Ownership of widget is transferred to the popup menu or to the menu bar. So don't go deleting it yourself, bestie, that's somebody else's problem now π«Ά
Now for the real talk. Theoretically, any widget can be inserted into a popup menu. In practice? Only certain widgets make sense. It's giving "you can wear that, but should you" π
If a widget is not focus-enabled (peep QWidget::isFocusEnabled()), the menu treats it as a separator β meaning the item is not selectable and will never get focus. So if you want a popup menu with a title, you can literally just insert a QLabel and it just works. iconic β¨
If the widget is focus-enabled, it will get focus when the user traverses the popup menu with the arrow keys. And if the widget doesn't accept ArrowUp and ArrowDown in its key event handler, the focus moves back to the menu when the respective arrow key is hit one more time. Works with a QLineEdit, for example. But if the widget accepts the arrow key itself, it must also provide a way to put focus back on the menu by calling QWidget::focusNextPrevChild(). Futhermore β and this is the important one, no cap β if the embedded widget closes the menu when the user made a selection, do it 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 )
Again: This is an overloaded member function, provided for convenience. It behaves essentially like the above function. Same energy, different parameters π
Inserts a custom menu item custom with an icon, with optional id id, and optional index position.
Heads up bestie: 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 )
Yep, another one β This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Inserts a custom menu item custom with optional id id, and optional index position.
Same warning, same stakes: this only works with popup menus, it is not supported for menu bars, and 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. If index is negative, the separator becomes the last menu item. Simple as π¦
How it looks depends on your platform, and honestly the drama is unmatched:
- 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") get drawn right-justified.
- In a Windows menu bar, separators are ignored entirely (to comply with the Windows style guidelines). bestie just vanishes π
Examples: yep, the docs point you at examples for this one.
bool QMenuData::isItemActive ( int id ) const
Returns TRUE if the menu item with the id id is currently active; otherwise returns FALSE. That's it, that's the function π
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: yes bestie, examples exist.
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 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. Sneaky little default, love that for us β¨
See also connectItem(), disconnectItem(), and setItemParameter().
void QMenuData::menuContentsChanged () [virtual protected]
Virtual function; it notifies subclasses that one or more items have been inserted or removed. It's the "hey bestie, the menu changed" ping π£
Reimplemented in QMenuBar.
void QMenuData::menuDelPopup ( QPopupMenu * ) [virtual protected]
Virtual function; notifies subclasses that a popup menu item has been removed. π«‘
void QMenuData::menuInsPopup ( QPopupMenu * ) [virtual protected]
Virtual function; notifies subclasses that a popup menu item has been inserted. Opposite twin of the last one π
void QMenuData::menuStateChanged () [virtual protected]
Virtual function; notifies subclasses that one or more items have changed state β that's enabled/disabled, or checked/unchecked. The glow-up got announced π
Reimplemented in QMenuBar.
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. No pixmap? You get a zero, not a vibe πΈ
See also changeItem(), text(), and iconSet().
void QMenuData::removeItem ( int id )
Removes the menu item that has the identifier id. Bye bestie, we hardly knew ye π
See also removeItemAt() and clear().
Example: chart/chartform.cpp.
void QMenuData::removeItemAt ( int index )
Removes the menu item at position index. Position-based instead of id-based, choose your fighter π
See also removeItem() and clear().
void QMenuData::setAccel ( const QKeySequence & key, int id )
Sets the accelerator key for the menu item id to key. Keyboard shortcuts, the moment we've all been waiting for β¨οΈβ¨
An accelerator key consists of a key code and a combination of the modifiers SHIFT, CTRL, ALT or UNICODE_ACCEL (OR'ed or added). The header file qnamespace.h contains a list of key codes β go look, it's all there.
Defining an accelerator key produces a text that gets added to the menu item; for instance, CTRL + Key_O produces "Ctrl+O". The text is formatted differently for different platforms, because of course it is π
Note this, fr fr: keyboard accelerators in Qt are not application-global. Instead they are bound to a certain top-level window. For example, accelerators inQPopupMenuitems only work for menus that are associated with a certain window. This is true for popup menus that live in a menu bar, since their accelerators will then be installed in the menu bar itself. This also applies to stand-alone popup menus that have a top-level widget in theirparentWidget()chain β the menu will then install its accelerator object on that top-level widget. For all other cases, use an independentQAccelobject.
Example:
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:
fileMenu->setAccel( tr("Ctrl+O"), 67 );
You can also specify the accelerator in the insertItem() function. And you may prefer to use QAction to associate accelerators with menu items β that's the modern main character move, iykyk π
See also accel(), insertItem(), QAccel, and QAction.
Example: menu/menu.cpp.
void QMenuData::setId ( int index, int id ) [virtual]
Sets the menu identifier of the item at index to id.
If index is out of range, the operation is ignored β no error, no drama, just silence π«Ά
See also idAt().
void QMenuData::setItemChecked ( int id, bool check )
If check is TRUE, checks the menu item with id id; otherwise unchecks the menu item with id id. It calls QPopupMenu::setCheckable( TRUE ) if necessary β handles that for you, we love a self-sufficient function π
See also isItemChecked().
Examples: yes, examples are a thing here.
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. Toggle queen π
See also isItemEnabled().
Examples: indeed, examples exist.
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 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. Poof, gone, or poof, back π
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. Contextual help, we stan a helpful menu π
See also whatsThis().
Examples: you guessed it, 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. Empty menu item = null string, that's the deal β¨
See also changeItem(), pixmap(), and iconSet().
Examples: yes bestie, examples.
void QMenuData::updateItem ( int id ) [virtual]
Virtual function; notifies subclasses about an item with id id that has been changed. Glow-up announcement, take two π£
Reimplemented in QPopupMenu.
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. No text yet? You get null, no hard feelings πΈ
See also setWhatsThis().
π SEE ALSO π
π COPYRIGHT π
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. (so like, the source code wrote it, not a human β slay, I guess π )
π 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. (fr fr, good bug reports are the love language of every maintainer π«Ά)
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. (so yeah, this whole thing is a fan-favorite side quest, not the canon π)
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qmenudata.3qt) and the Qt version (3.3.8).
okay bestie that's the whole thing β Trolltech AS, dated 2 February 2007, page QMenuData(3qt). go forth and build menus, you absolute icon πβ¨π
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms