com.trolltech.qt.gui
Class QShortcut

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QShortcut
All Implemented Interfaces:
QtJambiInterface

public class QShortcut
extends QObject

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.

On certain widgets, using '&' in front of a character will autmatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcut Alt+X (use '&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the Alt key, but this is a setting the user can change. On Mac such shortcuts do not exists, unless you explicitly call the global qt_set_sequence_auto_mnemonic() function; then they will appear as they do on X11.

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 = new 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, QAction

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal0 activated
          This signal is emitted when the user types the shortcut's key sequence.
 QSignalEmitter.Signal0 activatedAmbiguously
          This signal is emitted when the user types a shortcut key sequence that is ambiguous.
 
Constructor Summary
QShortcut(QKeySequence key, QWidget parent)
          This is an overloaded constructor provided for convenience.
QShortcut(QKeySequence key, QWidget parent, Qt.ShortcutContext context)
          This is an overloaded constructor provided for convenience.
QShortcut(QWidget parent)
          Constructs a QShortcut object for the parent widget.
 
Method Summary
 boolean autoRepeat()
          Returns whether the shortcut can auto repeat.
 Qt.ShortcutContext context()
          Returns the context in which the shortcut is valid.
 boolean event(QEvent e)
          This function is reimplemented for internal reasons.
static QShortcut fromNativePointer(QNativePointer nativePointer)
          This function returns the QShortcut instance pointed to by nativePointer
 int id()
          Returns the shortcut's ID.
 boolean isEnabled()
          Returns whether the shortcut is enabled.
 QKeySequence key()
          Returns the shortcut's key sequence.
 QWidget parentWidget()
          Returns the shortcut's parent widget.
 void setAutoRepeat(boolean on)
          Sets whether the shortcut can auto repeat to on.
 void setContext(Qt.ShortcutContext context)
          Sets the context in which the shortcut is valid to context.
 void setEnabled(boolean enable)
          Sets whether the shortcut is enabled to enable.
 void setKey(QKeySequence key)
          Sets the shortcut's key sequence to key.
 void setWhatsThis(java.lang.String text)
          Sets the shortcut's "What's This?" help text to text.
 java.lang.String whatsThis()
          Returns the shortcut's "What's This?" help text.
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

activated

public final QSignalEmitter.Signal0 activated

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

Compatible Slot Signature:
void mySlot()
See Also:
activatedAmbiguously


activatedAmbiguously

public final QSignalEmitter.Signal0 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.

Compatible Slot Signature:
void mySlot()
See Also:
activated

Constructor Detail

QShortcut

public QShortcut(QWidget parent)

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

public QShortcut(QKeySequence key,
                 QWidget parent)
This is an overloaded constructor provided for convenience.


QShortcut

public QShortcut(QKeySequence key,
                 QWidget parent,
                 Qt.ShortcutContext context)
This is an overloaded constructor provided for convenience.

Method Detail

autoRepeat

public final boolean autoRepeat()

Returns whether the shortcut can auto repeat.

If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.

See Also:
setAutoRepeat

context

public final Qt.ShortcutContext context()

Returns the context in which the shortcut is valid.

A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is Qt::WindowShortcut, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.

See Also:
setContext

id

public final int id()

Returns the shortcut's ID.

See Also:
QShortcutEvent::shortcutId

isEnabled

public final boolean isEnabled()

Returns whether the shortcut is enabled.

An enabled shortcut emits the activated or activatedAmbiguously signal when a QShortcutEvent occurs that matches the shortcut's key sequence.

If the application is in WhatsThis mode the shortcut will not emit the signals, but will show the "What's This?" text instead.

See Also:
whatsThis

key

public final QKeySequence key()

Returns the shortcut's key sequence.

This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:

    setKey(0);                  // no signal emitted
    setKey(QKeySequence());     // no signal emitted
    setKey(0x3b1);              // Greek letter alpha
    setKey(Qt::Key_D);              // 'd', e.g. to delete
    setKey('q');                // 'q', e.g. to quit
    setKey(Qt::CTRL + Qt::Key_P);       // Ctrl+P, e.g. to print document
    setKey("Ctrl+P");           // Ctrl+P, e.g. to print document

See Also:
setKey

parentWidget

public final QWidget parentWidget()

Returns the shortcut's parent widget.


setAutoRepeat

public final void setAutoRepeat(boolean on)

Sets whether the shortcut can auto repeat to on.

If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.

See Also:
autoRepeat

setContext

public final void setContext(Qt.ShortcutContext context)

Sets the context in which the shortcut is valid to context.

A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is Qt::WindowShortcut, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.

See Also:
context

setEnabled

public final void setEnabled(boolean enable)

Sets whether the shortcut is enabled to enable.

An enabled shortcut emits the activated or activatedAmbiguously signal when a QShortcutEvent occurs that matches the shortcut's key sequence.

If the application is in WhatsThis mode the shortcut will not emit the signals, but will show the "What's This?" text instead.

See Also:
isEnabled, whatsThis

setKey

public final void setKey(QKeySequence key)

Sets the shortcut's key sequence to key.

This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:

    setKey(0);                  // no signal emitted
    setKey(QKeySequence());     // no signal emitted
    setKey(0x3b1);              // Greek letter alpha
    setKey(Qt::Key_D);              // 'd', e.g. to delete
    setKey('q');                // 'q', e.g. to quit
    setKey(Qt::CTRL + Qt::Key_P);       // Ctrl+P, e.g. to print document
    setKey("Ctrl+P");           // Ctrl+P, e.g. to print document

See Also:
key

setWhatsThis

public final void setWhatsThis(java.lang.String text)

Sets the shortcut's "What's This?" help text to text.

The text will be shown when the application is in "What's This?" mode and the user types the shortcut key sequence.

To set "What's This?" help on a menu item (with or without a shortcut key), set the help on the item's action.

See Also:
whatsThis, QWhatsThis::inWhatsThisMode, QAction::setWhatsThis

whatsThis

public final java.lang.String whatsThis()

Returns the shortcut's "What's This?" help text.

The text will be shown when the application is in "What's This?" mode and the user types the shortcut key sequence.

To set "What's This?" help on a menu item (with or without a shortcut key), set the help on the item's action.

See Also:
QWhatsThis::inWhatsThisMode, QAction::setWhatsThis

event

public boolean event(QEvent e)

This function is reimplemented for internal reasons.

Overrides:
event in class QObject
See Also:
installEventFilter, timerEvent, QApplication::sendEvent, QApplication::postEvent, QWidget::event

fromNativePointer

public static QShortcut fromNativePointer(QNativePointer nativePointer)
This function returns the QShortcut instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.