QtBase
v6.3.1
|
The QShortcut class is used to create keyboard shortcuts. More...
#include <qshortcut.h>
Signals | |
void | activated () |
void | activatedAmbiguously () |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
Protected Member Functions | |
bool | event (QEvent *e) override |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Properties | |
QKeySequence | key |
the shortcut's primary key sequence More... | |
bool | enabled |
whether the shortcut is enabled More... | |
bool | autoRepeat |
whether the shortcut can auto repeat More... | |
Qt::ShortcutContext | context |
the context in which the shortcut is valid More... | |
Properties inherited from QObject | |
QString | objectName |
the name of this object More... | |
The QShortcut class is used to create keyboard shortcuts.
\inmodule QtGui
The QShortcut class provides a way of connecting keyboard shortcuts to Qt's \l{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 \uicontrol Shift, \uicontrol Ctrl, and \uicontrol Alt.
\target mnemonic
In widget applications, certain widgets can use '&' in front of a character. This will automatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcut \uicontrol 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 \uicontrol Alt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call \l qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut character underlined.
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:
When the user types the \l{QKeySequence}{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().
Definition at line 54 of file qshortcut.h.
|
explicit |
|
explicit |
Constructs a QShortcut object for the parent, which should be a QWindow or a QWidget.
The shortcut operates on its parent, listening for \l{QShortcutEvent}s 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.
Definition at line 214 of file qshortcut.cpp.
|
explicit |
The shortcut operates on its parent, listening for \l{QShortcutEvent}s that match the standardKey. 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.
Definition at line 241 of file qshortcut.cpp.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
QShortcut::~QShortcut | ( | ) |
Destroys the shortcut.
Definition at line 372 of file qshortcut.cpp.
|
signal |
This signal is emitted when the user types the shortcut's key sequence.
|
signal |
When a key sequence is being typed at the keyboard, it is said to be ambiguous as long as it matches the start of more than one shortcut.
When a shortcut's key sequence is completed, activatedAmbiguously() is emitted if the key sequence is still ambiguous (i.e., it is the start of one or more other shortcuts). The activated() signal is not emitted in this case.
bool QShortcut::autoRepeat | ( | ) | const |
Definition at line 531 of file qshortcut.cpp.
Qt::ShortcutContext QShortcut::context | ( | ) | const |
Definition at line 505 of file qshortcut.cpp.
|
overrideprotectedvirtual |
This virtual function receives events to an object and should return true if the event e was recognized and processed.
The event() function can be reimplemented to customize the behavior of an object.
Make sure you call the parent event class implementation for all the events you did not handle.
Example:
Reimplemented from QObject.
Definition at line 595 of file qshortcut.cpp.
bool QShortcut::isEnabled | ( | ) | const |
Definition at line 477 of file qshortcut.cpp.
QKeySequence QShortcut::key | ( | ) | const |
Definition at line 400 of file qshortcut.cpp.
QList< QKeySequence > QShortcut::keys | ( | ) | const |
Returns the list of key sequences which trigger this shortcut.
Definition at line 445 of file qshortcut.cpp.
void QShortcut::setAutoRepeat | ( | bool | on | ) |
void QShortcut::setContext | ( | Qt::ShortcutContext | context | ) |
void QShortcut::setEnabled | ( | bool | enable | ) |
void QShortcut::setKey | ( | const QKeySequence & | key | ) |
void QShortcut::setKeys | ( | const QList< QKeySequence > & | keys | ) |
Sets keys as the list of key sequences that trigger the shortcut.
Definition at line 416 of file qshortcut.cpp.
void QShortcut::setKeys | ( | QKeySequence::StandardKey | key | ) |
Sets the triggers to those matching the standard key key.
Definition at line 433 of file qshortcut.cpp.
Sets the shortcut's "What's This?" help text.
The text will be shown when a widget 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.
By default, the help text is an empty string.
This function has no effect in applications that don't use widgets.
Definition at line 554 of file qshortcut.cpp.
QString QShortcut::whatsThis | ( | ) | const |
Returns the shortcut's "What's This?" help text.
Definition at line 565 of file qshortcut.cpp.
|
readwrite |
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.
Definition at line 233 of file qshortcut.h.
|
readwrite |
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.
By default, this property is set to Qt::WindowShortcut.
Definition at line 233 of file qshortcut.h.
|
readwrite |
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.
By default, this property is true
.
Definition at line 233 of file qshortcut.h.
|
readwrite |
the shortcut's primary 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:
By default, this property contains an empty key sequence.
Definition at line 233 of file qshortcut.h.