Qt Toolkit - QAccel Class

# QAccel Class Reference

The QAccel class handles keyboard accelerator keys. More...

`#include <qaccel.h>`

Inherits QObject.

List of all member functions.

## Public Members

- QAccel ( QWidget * parent, const char * name=0 )
- ~QAccel ()
- bool isEnabled () const
- void setEnabled ( bool )
- uint count () const
- int insertItem ( int key, int id=-1 )
- void removeItem ( int id )
- void clear ()
- int key ( int id )
- int findKey ( int key ) const
- bool isItemEnabled ( int id ) const
- void 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 ()

## Signals

- void activated ( int id )

## Protected Members

- virtual bool eventFilter ( QObject *, QEvent * )

## Detailed Description

The QAccel class handles keyboard accelerator keys.

A QAccel contains a list of accelerator items. Each accelerator item consists of an identifier and a keyboard code combined with modifiers (`SHIFT, CTRL, ALT` or `ASCII_ACCEL).`

For example, `CTRL + Key_P` could be a shortcut for printing a document. The key codes are listed in qkeycode.h.

When pressed, an accelerator key 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()).

A QAccel object handles key events to the top level window containing parent, and hence to any child widgets of that window. Note that the accelerator will be deleted only when the parent is deleted, and will consume relevant key events until then.

Example:

         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::setAccel() and GUI Design Handbook: Keyboard Shortcuts,

Examples: application/application.cpp

## Member Function Documentation

### QAccel::QAccel ( QWidget * parent, const char * name=0 )

Creates a QAccel object with a parent widget and a name.

### QAccel::~QAccel ()

Destroys the accelerator object.

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

### void QAccel::clear ()

Removes all accelerator items.

### bool QAccel::connectItem ( int id, const QObject * receiver, const char * member )

Connects an accelerator item to a slot/signal in another object.

Arguments:

- id is the accelerator item id.
- receiver is the object to receive a signal.
- member is a slot or signal function in the receiver.

        a->connectItem( 201, mainView, SLOT(quit()) );

See also: disconnectItem().

Examples: application/application.cpp

### uint QAccel::count () const

Returns the number of accelerator items.

### bool QAccel::disconnectItem ( int id, const QObject * receiver, const char * member )

Disconnects an accelerator item from a function in another object.

See also: connectItem().

### bool QAccel::eventFilter ( QObject *, QEvent * e ) `[virtual protected]`

Processes accelerator events intended for the top level widget.

Reimplemented from QObject.

### int QAccel::findKey ( int key ) const

Returns the identifier of the accelerator item with the key code key, or -1 if the item cannot be found.

### int QAccel::insertItem ( int key, int id=-1 )

Inserts an accelerator item and returns the item's identifier.

Arguments:

- key is a key code plus a combination of SHIFT, CTRL and ALT.
- id is the accelerator item id.

If id is negative, then the item will be assigned a unique identifier.

        QAccel *a = new QAccel( myWindow );         // create accels for myWindow
        a->insertItem( Key_P + CTRL, 200 );         // Ctrl+P to print document
        a->insertItem( Key_X + ALT , 201 );         // Alt+X  to quit
        a->insertItem( ASCII_ACCEL + 'q', 202 );    // ASCII 'q' to quit
        a->insertItem( Key_D );                     // gets id 3
        a->insertItem( Key_P + CTRL + SHIFT );      // gets id 4

Examples: application/application.cpp

### bool QAccel::isEnabled () const

Returns TRUE if the accelerator is enabled, or FALSE if it is disabled.

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

### int QAccel::key ( int id )

Returns the key code of the accelerator item with the identifier id, or zero if the id cannot be found.

### void QAccel::removeItem ( int id )

Removes the accelerator item with the identifier id.

### void QAccel::repairEventFilter ()

Make sure that the accelerator is watching the correct event filter. Used by QWidget::recreate().

### void QAccel::setEnabled ( bool enable )

Enables the accelerator if enable is TRUE, or disables it if enable is FALSE.

Individual keys can also be enabled or disabled.

See also: isEnabled() and setItemEnabled().

### void QAccel::setItemEnabled ( int id, bool enable )

Enables or disables an accelerator item.

Arguments:

- id is the item identifier.
- enable specifies whether the item should be enabled or disabled.

See also: isItemEnabled() and isEnabled().

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.

It was generated from the following files:

- qaccel.h: 1998/08/21
- qaccel.cpp: 1998/07/03