QAccel(3qt)
QAccel(3qt) β the manual page, but make it cute πβ¨
okay so bestie, welcome to the QAccel(3qt) man page. it's all about keyboard accelerators and shortcut keys, and honestly? iconic. let's get into it. π
NAME β¨
QAccel β handles keyboard accelerator and shortcut keys. no cap. π
SYNOPSIS π¦
here's the vibe check on the synopsis, bestie:
#include <qaccel.h>
Inherits QObject.
Public Members π
QAccel ( QWidget * parent, const char * name = 0 )QAccel ( QWidget * watch, QObject * parent, const char * name = 0 )~QAccel ()bool isEnabled () constvoid setEnabled ( bool enable )uint count () constint insertItem ( const QKeySequence & key, int id = -1 )void removeItem ( int id )void clear ()QKeySequence key ( int id )int findKey ( const QKeySequence & key ) constbool isItemEnabled ( int id ) constvoid setItemEnabled ( int id, bool enable )bool connectItem ( int id, const QObject * receiver, const char * member )bool disconnectItem ( int id, const QObject * receiver, const char * member )void repairEventFilter ()(obsolete)void setWhatsThis ( int id, const QString & text )QString whatsThis ( int id ) const
Signals π£
void activated ( int id )void activatedAmbiguously ( int id )
Static Public Members π
QKeySequence shortcutKey ( const QString & str )QString keyToString ( QKeySequence k )(obsolete)QKeySequence stringToKey ( const QString & s )(obsolete)
Protected Members π‘οΈ
virtual bool eventFilter ( QObject *, QEvent * )(obsolete)
DESCRIPTION π
The QAccel class is the one that handles keyboard accelerator and shortcut keys. periodt.
So basically, a keyboard accelerator is like: you press a certain key combo and boom, an action triggers. The accelerator is the main character for all keyboard activity of every child of one top-level widget, so it's not affected by keyboard focus. lowkey powerful. β¨
Honestly? Most of the time you won't need to use this class directly, bestie. Use the QAction class to create actions with accelerators that work in both menus and toolbars. If you're only here for menus, use QMenuData::insertItem() or QMenuData::setAccel() to make accelerators for operations that are also available on menus. And a bunch of widgets automatically generate accelerators, like QButton, QGroupBox, QLabel (with QLabel::setBuddy()), QMenuBar and QTabBar. For example:
QPushButton p( "&Exit", parent ); // automatic shortcut ALT+Key_E
QPopupMenu *fileMenu = new fileMenu( parent );
fileMenu->insertItem( "Undo", parent, SLOT(undo()), CTRL+Key_Z );
A QAccel holds a list of accelerator items, and you can manipulate them with insertItem(), removeItem(), clear(), key() and findKey(). slay. π
Every accelerator item is made of an identifier and a QKeySequence. A single key sequence is a keyboard code plus modifiers (SHIFT, CTRL, ALT or UNICODE_ACCEL). Like, CTRL + Key_P could be your shortcut for printing a document. The key codes are all listed in qnamespace.h. Alternatively, you can use UNICODE_ACCEL with the unicode code point of the character. So UNICODE_ACCEL + 'A' gives you the same accelerator as Key_A. iconic. π
When you press an accelerator key, the accelerator emits the activated() signal with a number that identifies that specific accelerator item. You can also connect accelerator items individually, so two different keys can activate two different slots (check connectItem() and disconnectItem()). π«Ά
Here's the tea: the activated() signal does not get emitted when two or more accelerators match the same key. Instead, the first matching accelerator sends out the activatedAmbiguously() signal. And by pressing the key multiple times, users can navigate between all the matching accelerators. Some standard controls like QPushButton and QCheckBox connect the activatedAmbiguously() signal to the harmless setFocus() slot, while activated() is connected to a slot that invokes the button's action. Most controls, like QLabel and QTabBar, treat activated() and activatedAmbiguously() as equivalent. π
Use setEnabled() to enable or disable all the items in an accelerator, or setItemEnabled() to enable or disable individual items. An item is only active when both the QAccel and the item itself are enabled. periodt. π―
The function setWhatsThis() lets you set a help text that pops up when the user presses an accelerator key in What's This mode. cute. π
The accelerator gets deleted when parent is deleted, and it will consume relevant key events until then. so it's not just gonna hang around forever. π¦
Okay so note this, bestie: the accelerator
accelerator->insertItem( QKeySequence("M") );
can be triggered with both the 'M' key and with Shift+M, unless you define a second accelerator for the Shift+M combination. so watch out for that. π
Example time:
QAccel *a = new QAccel( myWindow ); // create accels for myWindow
a->connectItem( a->insertItem(Key_P+CTRL), // adds Ctrl+P accelerator
myWindow, // connected to myWindow's
SLOT(printDoc()) ); // printDoc() slot
See also QKeyEvent, QWidget::keyPressEvent(), QMenuData::setAccel(), QButton::accel, QLabel::setBuddy(), QKeySequence, GUI Design Handbook: Keyboard Shortcuts, and Miscellaneous Classes. π
MEMBER FUNCTION DOCUMENTATION π
QAccel::QAccel ( QWidget * parent, const char * name = 0 )
okay so this constructor makes a QAccel object called name, with parent parent. The accelerator operates on parent. easy. β¨
QAccel::QAccel ( QWidget * watch, QObject * parent, const char * name = 0 )
This one constructs a QAccel object called name, that operates on watch, and is a child of parent.
But lowkey, this constructor is not needed for normal application programming. so don't stress about it. π
QAccel::~QAccel ()
Destroys the accelerator object and frees all allocated resources. bye bye π
void QAccel::activated ( int id ) [signal]
This signal is emitted when an accelerator key is pressed. id is a number that identifies this particular accelerator item.
See also activatedAmbiguously(). π£
void QAccel::activatedAmbiguously ( int id ) [signal]
This signal is emitted when an accelerator key is pressed. id is a number that identifies this particular accelerator item.
See also activated(). π£
void QAccel::clear ()
Removes all accelerator items. clean slate β¨
bool QAccel::connectItem ( int id, const QObject * receiver, const char * member )
Connects the accelerator item id to the slot member of receiver.
a->connectItem( 201, mainView, SLOT(quit()) );
And yes, you can also send a signal as member. versatile. π
Normally, accelerators are connected to slots that then receive the activated(int id) signal with the id of the accelerator item that was activated. But if you choose to connect a specific accelerator item using this function, the activated() signal is emitted if the associated key sequence is pressed, but no activated(int id) signal is emitted. got it? π«Ά
See also disconnectItem().
Example: t14/gamebrd.cpp.
uint QAccel::count () const
Returns the number of accelerator items in this accelerator. simple math π
bool QAccel::disconnectItem ( int id, const QObject * receiver, const char * member )
Disconnects an accelerator item with id id from the function called member in the receiver object.
See also connectItem(). π
bool QAccel::eventFilter ( QObject *, QEvent * ) [virtual protected]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. serves no purpose anymore. so yeah, don't use it. π
Reimplemented from QObject.
int QAccel::findKey ( const QKeySequence & key ) const
Returns the identifier of the accelerator item with the key code key, or -1 if the item cannot be found. detective work π
int QAccel::insertItem ( const QKeySequence & key, int id = -1 )
Inserts an accelerator item and returns the item's identifier.
key is a key code plus an optional combination of SHIFT, CTRL and ALT. id is the accelerator item id.
If id is negative, then the item gets assigned a unique negative identifier less than -1.
QAccel *a = new QAccel( myWindow ); // create accels for myWindow
a->insertItem( CTRL + Key_P, 200 ); // Ctrl+P, e.g. to print document
a->insertItem( ALT + Key_X, 201 ); // Alt+X, e.g. to quit
a->insertItem( UNICODE_ACCEL + 'q', 202 ); // Unicode 'q', e.g. to quit
a->insertItem( Key_D ); // gets a unique negative id < -1
a->insertItem( CTRL + SHIFT + Key_P ); // gets a unique negative id < -1
Example: t14/gamebrd.cpp.
bool QAccel::isEnabled () const
Returns TRUE if the accelerator is enabled; otherwise returns FALSE.
See also setEnabled() and isItemEnabled(). β
bool QAccel::isItemEnabled ( int id ) const
Returns TRUE if the accelerator item with the identifier id is enabled. Returns FALSE if the item is disabled or cannot be found.
See also setItemEnabled() and isEnabled(). β
QKeySequence QAccel::key ( int id )
Returns the key sequence of the accelerator item with identifier id, or an invalid key sequence (0) if the id cannot be found. π
QString QAccel::keyToString ( QKeySequence k ) [static]
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Creates an accelerator string for the key k. For instance CTRL+Key_O gives "Ctrl+O". The "Ctrl" etc. are translated (using QObject::tr()) in the "QAccel" context.
The function is superfluous. Just cast the QKeySequence k to a QString for the same effect. no need for extra steps. π
void QAccel::removeItem ( int id )
Removes the accelerator item with the identifier id. yeet. ποΈ
void QAccel::repairEventFilter ()
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. serves no purpose anymore. so skip it. π
void QAccel::setEnabled ( bool enable )
Enables the accelerator if enable is TRUE, or disables it if enable is FALSE.
You can also enable or disable individual keys with setItemEnabled(). To work, a key must be an enabled item in an enabled QAccel.
See also isEnabled() and setItemEnabled(). β‘
void QAccel::setItemEnabled ( int id, bool enable )
Enables the accelerator item with the identifier id if enable is TRUE, and disables item id if enable is FALSE.
To work, an item must be enabled and be in an enabled QAccel.
See also isItemEnabled() and isEnabled(). β‘
void QAccel::setWhatsThis ( int id, const QString & text )
Sets a What's This help text for the accelerator item id to text.
The text will be shown when the application is in What's This mode and the user hits the accelerator key.
To set What's This help on a menu item (with or without an accelerator key), use QMenuData::setWhatsThis().
See also whatsThis(), QWhatsThis::inWhatsThisMode(), QMenuData::setWhatsThis(), and QAction::whatsThis. π
β¨ QKeySequence QAccel::shortcutKey ( const QString & str ) [static] β¨
Okay so this one is a static lil bestie that returns the shortcut key sequence for str, or an invalid key sequence (0) if str has no shortcut sequence at all. No cap. π
For example, shortcutKey("E&xit") returns ALT+Key_X, shortcutKey("&Quit") returns ALT+Key_Q and shortcutKey("Quit") returns 0. (In code that does not inherit the Qt namespace class, you must write e.g. Qt::ALT+Qt::Key_Q.)
We provide a list of common accelerators in English. At the time of writing, Microsoft and Open Group do not appear to have issued equivalent recommendations for other languages. It's giving very English-coded, bestie. π
π QKeySequence QAccel::stringToKey ( const QString & s ) [static] π
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code. π¨
Returns an accelerator code for the string s. For example, " Ctrl+O" gives CTRL+UNICODE_ACCEL+'O'. The strings "Ctrl", " Shift", "Alt" are recognized, as well as their translated equivalents in the "QAccel" context (using QObject::tr()). Returns 0 if s is not recognized.
This function is typically used with tr(), so that accelerator keys can be replaced in translations:
QPopupMenu *file = new QPopupMenu( this );
file->insertItem( p1, tr("&Open..."), this, SLOT(open()),
QAccel::stringToKey(tr("Ctrl+O", "File|Open")) );
Notice the "File|Open" translator comment. It is by no means necessary, but it provides some context for the human translator. So like, it's a lil note for the translator bestie. π«Ά
The function is superfluous. Construct a QKeySequence from the string s for the same effect. It's giving legacy energy, honestly.
See also QObject::tr() and Internationalization with Qt.
Example: i18n/mywidget.cpp.
π QString QAccel::whatsThis ( int id ) const π
Returns the What's This help text for the specified item id or QString::null if no text has been specified. So if it's empty, you get the null vibes. π
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 it's not like a human author sat there writing this by hand, it's a robot-generated moment. π€π
π 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. iykyk β man pages are a vibe, but they're not the official main character here. π
If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qaccel.3qt) and the Qt version (3.3.8). Help a bestie out! π
And that's the tea, bestie! This page came from Trolltech AS, dated 2 February 2007, for QAccel(3qt) πβ¨
π¦ 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