The QAccel class handles keyboard accelerator and shortcut keys.
.PP
A keyboard accelerator triggers an action when a certain key combination is pressed. The accelerator handles all keyboard activity for all the children of one top-level widget, so it is not affected by the keyboard focus.
In most cases, you will not need to use this class directly. Use the TQAction class to create actions with accelerators that can be used in both menus and toolbars. If you're only interested in menus use TQMenuData::insertItem() or TQMenuData::setAccel() to make accelerators for operations that are also available on menus. Many widgets automatically generate accelerators, such as QButton, QGroupBox, TQLabel (with TQLabel::setBuddy()), TQMenuBar and QTabBar. Example:
Each accelerator item consists of an identifier and a QKeySequence. A single key sequence consists of a keyboard code combined with modifiers (SHIFT, CTRL, ALT or UNICODE_ACCEL). For example, \fCCTRL + Key_P\fR could be a shortcut for printing a document. The key codes are listed in ntqnamespace.h. As an alternative, use UNICODE_ACCEL with the unicode code point of the character. For example, \fCUNICODE_ACCEL + 'A'\fR gives the same accelerator as Key_A.
When an accelerator key is pressed, the accelerator sends out the signal activated() with a number that identifies this particular accelerator item. Accelerator items can also be individually connected, so that two different keys will activate two different slots (see connectItem() and disconnectItem()).
The activated() signal is \fInot\fR emitted when two or more accelerators match the same key. Instead, the first matching accelerator sends out the activatedAmbiguously() signal. By pressing the key multiple times, users can navigate between all matching accelerators. Some standard controls like TQPushButton and TQCheckBox connect the activatedAmbiguously() signal to the harmless setFocus() slot, whereas activated() is connected to a slot invoking the button's action. Most controls, like TQLabel 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 active only when both the QAccel and the item itself are enabled.
.PP
The function setWhatsThis() specifies a help text that appears when the user presses an accelerator key in What's This mode.
.PP
The accelerator will be deleted when \fIparent\fR is deleted, and will consume relevant key events until then.
.PP
Please note that the accelerator
.PP
.nf
.br
accelerator->insertItem( QKeySequence("M") );
.br
.fi
can be triggered with both the 'M' key, and with Shift+M, unless a second accelerator is defined for the Shift+M combination.
.PP
Example:
.PP
.nf
.br
QAccel *a = new QAccel( myWindow ); // create accels for myWindow
Of course, you can also send a signal as \fImember\fR.
.PP
Normally accelerators are connected to slots which then receive the \fCactivated(int id)\fR signal with the id of the accelerator item that was activated. 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 \fCactivated(int id)\fR signal is emitted.
.PP
See also disconnectItem().
.PP
Example: t14/gamebrd.cpp.
.SH "uint QAccel::count () const"
Returns the number of accelerator items in this accelerator.
Creates an accelerator string for the key \fIk\fR. For instance CTRL+Key_O gives "Ctrl+O". The "Ctrl" etc. are translated (using TQObject::tr()) in the "QAccel" context.
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 TQt namespace class, you must write e.g. TQt::ALT+TQt::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.
Returns an accelerator code for the string \fIs\fR. 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 TQObject::tr()). Returns 0 if \fIs\fR is not recognized.