
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQShortcut class is used to create keyboard shortcuts.More...
| Header: | #include <QShortcut> |
| Inherits: | QObject |
|
| QShortcut(QWidget * parent) | |
| QShortcut(const QKeySequence & key, QWidget * parent, const char * member = 0, const char * ambiguousMember = 0, Qt::ShortcutContext context = Qt::WindowShortcut) | |
| ~QShortcut() | |
| bool | autoRepeat() const |
| Qt::ShortcutContext | context() |
| int | id() const |
| bool | isEnabled() const |
| QKeySequence | key() const |
| QWidget * | parentWidget() const |
| void | setAutoRepeat(bool on) |
| void | setContext(Qt::ShortcutContext context) |
| void | setEnabled(bool enable) |
| void | setKey(const QKeySequence & key) |
| void | setWhatsThis(const QString & text) |
| QString | whatsThis() const |
| void | activated() |
| void | activatedAmbiguously() |
TheQShortcut class is used to create keyboard shortcuts.
TheQShortcut class provides a way of connecting keyboard shortcuts to Qt'ssignals 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 asShift,Ctrl, andAlt.
On certain widgets, using '&' in front of a character will automatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcutAlt+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 theAlt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Callqt_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 theQMenu class to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in theQAction class.
The simplest way to create a shortcut for a particular widget is to construct the shortcut with a key sequence. For example:
shortcut=newQShortcut(QKeySequence(tr("Ctrl+O","File|Open")), parent);
When the user types thekey sequence for a given shortcut, the shortcut'sactivated() signal is emitted. (In the case of ambiguity, theactivatedAmbiguously() 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 withsetKey() and retrieved withkey(). A shortcut can be enabled or disabled withsetEnabled(), and can have "What's This?" help text set withsetWhatsThis().
See alsoQShortcutEvent,QKeySequence, andQAction.
This property holds 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.
This property was introduced in Qt 4.2.
Access functions:
| bool | autoRepeat() const |
| void | setAutoRepeat(bool on) |
This property holds 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 isQt::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 toQt::WindowShortcut.
Access functions:
| Qt::ShortcutContext | context() |
| void | setContext(Qt::ShortcutContext context) |
This property holds whether the shortcut is enabled.
An enabled shortcut emits theactivated() oractivatedAmbiguously() signal when aQShortcutEvent occurs that matches the shortcut'skey() sequence.
If the application is inWhatsThis mode the shortcut will not emit the signals, but will show the "What's This?" text instead.
By default, this property is true.
Access functions:
| bool | isEnabled() const |
| void | setEnabled(bool enable) |
See alsowhatsThis.
This property holds 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 emittedsetKey(QKeySequence());// no signal emittedsetKey(0x3b1);// Greek letter alphasetKey(Qt::Key_D);// 'd', e.g. to deletesetKey('q');// 'q', e.g. to quitsetKey(Qt::CTRL+Qt::Key_P);// Ctrl+P, e.g. to print documentsetKey("Ctrl+P");// Ctrl+P, e.g. to print document
By default, this property contains an empty key sequence.
Access functions:
| QKeySequence | key() const |
| void | setKey(const QKeySequence & key) |
This property holds 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 shortcutkey() 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, this property contains an empty string.
Access functions:
| QString | whatsThis() const |
| void | setWhatsThis(const QString & text) |
See alsoQWhatsThis::inWhatsThisMode() andQAction::setWhatsThis().
Constructs aQShortcut object for theparent widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.
See alsosetKey().
Constructs aQShortcut object for theparent widget. The shortcut operates on its parent, listening forQShortcutEvents that match thekey sequence. Depending on the ambiguity of the event, the shortcut will call themember function, or theambiguousMember function, if the key press was in the shortcut'scontext.
Destroys the shortcut.
[signal]void QShortcut::activated()This signal is emitted when the user types the shortcut's key sequence.
See alsoactivatedAmbiguously().
[signal]void QShortcut::activatedAmbiguously()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). Theactivated() signal is not emitted in this case.
See alsoactivated().
Returns the shortcut's ID.
See alsoQShortcutEvent::shortcutId().
Returns the shortcut's parent widget.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.