Home · All Classes · Modules

QShortcut Class Reference
[QtGui module]

The QShortcut class is used to create keyboard shortcuts. More...

Inherits QObject.

Methods

Qt Signals


Detailed Description

The QShortcut class is used to create keyboard shortcuts.

The QShortcut class provides a way of connecting keyboard shortcuts to Qt's signals and slots mechanism, so that objects can be informed when a shortcut is executed. The shortcut can be set up to contain all the key presses necessary to describe a keyboard shortcut, including the states of modifier keys such as Shift, Ctrl, and Alt.

For applications that use menus, it may be more convenient to use the convenience functions provided in the QMenu class to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in the QAction class.

The simplest way to create a shortcut for a particular widget is to construct the shortcut with a key sequence. For example:

    shortcut = QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")),
                         parent);

When the user types the key sequence for a given shortcut, the shortcut's activated() signal is emitted. (In the case of ambiguity, the activatedAmbiguously() signal is emitted.) A shortcut is "listened for" by Qt's event loop when the shortcut's parent widget is receiving events.

A shortcut's key sequence can be set with setKey() and retrieved with key(). A shortcut can be enabled or disabled with setEnabled(), and can have "What's This?" help text set with setWhatsThis().

See also QShortcutEvent, QKeySequence, and QAction.


Method Documentation

QShortcut.__init__ (self, QWidget parent)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QShortcut object for the parent widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.

See also setKey().

QShortcut.__init__ (self, QKeySequence key, QWidget parent, SLOT() member = 0, SLOT() ambiguousMember = 0, Qt.ShortcutContext context = Qt.WindowShortcut)

The parent argument, if not None, causes self to be owned by Qt instead of PyQt.

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

Qt.ShortcutContext QShortcut.context (self)

bool QShortcut.event (self, QEvent e)

int QShortcut.id (self)

Returns the shortcut's ID.

See also QShortcutEvent.shortcutId().

bool QShortcut.isEnabled (self)

QKeySequence QShortcut.key (self)

QWidget QShortcut.parentWidget (self)

Returns the shortcut's parent widget.

QShortcut.setContext (self, Qt.ShortcutContext context)

QShortcut.setEnabled (self, bool enable)

QShortcut.setKey (self, QKeySequence key)

QShortcut.setWhatsThis (self, QString text)

QString QShortcut.whatsThis (self)


Qt Signal Documentation

void activated ()

This signal is emitted when the user types the shortcut's key sequence.

See also activatedAmbiguously().

void activatedAmbiguously ()

This signal is emitted when the user types a shortcut key sequence that is ambiguous. For example, if one key sequence is a "prefix" for another and the user types these keys it isn't clear if they want the shorter key sequence, or if they're about to type more to complete the longer key sequence.

See also activated().


PyQt 4.0.1 for X11Copyright © Riverbank Computing Ltd and Trolltech AS 2006Qt 4.1.4