Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
The QShortcut class is used to create keyboard shortcuts. More...
#include <qshortcut.h>
Signals | |
void | activated () |
This signal is emitted when the user types the shortcut's key sequence. | |
void | 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. | |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QShortcut (QObject *parent) | |
Constructs a QShortcut object for the parent, which should be a QWindow or a QWidget. | |
QShortcut (const QKeySequence &key, QObject *parent, const char *member=nullptr, const char *ambiguousMember=nullptr, Qt::ShortcutContext context=Qt::WindowShortcut) | |
Constructs a QShortcut object for the parent, which should be a QWindow or a QWidget. | |
QShortcut (QKeySequence::StandardKey key, QObject *parent, const char *member=nullptr, const char *ambiguousMember=nullptr, Qt::ShortcutContext context=Qt::WindowShortcut) | |
template<typename Func1 > | |
QShortcut (const QKeySequence &key, QObject *parent, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut) | |
template<class Obj1 , typename Func1 > | |
QShortcut (const QKeySequence &key, QObject *parent, const Obj1 *object1, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0) | |
template<class Obj1 , typename Func1 , typename Func2 > | |
QShortcut (const QKeySequence &key, QObject *parent, const Obj1 *object1, Func1 slot1, Func2 slot2, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0) | |
template<class Obj1 , typename Func1 , class Obj2 , typename Func2 > | |
QShortcut (const QKeySequence &key, QObject *parent, const Obj1 *object1, Func1 slot1, const Obj2 *object2, Func2 slot2, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj2 * >::Value >::type *=0) | |
template<typename Func1 > | |
QShortcut (QKeySequence::StandardKey key, QObject *parent, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut) | |
template<class Obj1 , typename Func1 > | |
QShortcut (QKeySequence::StandardKey key, QObject *parent, const Obj1 *object1, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0) | |
template<class Obj1 , typename Func1 , typename Func2 > | |
QShortcut (QKeySequence::StandardKey key, QObject *parent, const Obj1 *object1, Func1 slot1, Func2 slot2, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0) | |
template<class Obj1 , typename Func1 , class Obj2 , typename Func2 > | |
QShortcut (QKeySequence::StandardKey key, QObject *parent, const Obj1 *object1, Func1 slot1, const Obj2 *object2, Func2 slot2, Qt::ShortcutContext context=Qt::WindowShortcut, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj1 * >::Value >::type *=0, typename std::enable_if< QtPrivate::IsPointerToTypeDerivedFromQObject< Obj2 * >::Value >::type *=0) | |
~QShortcut () | |
Destroys the shortcut. | |
void | setKey (const QKeySequence &key) |
QKeySequence | key () const |
void | setKeys (QKeySequence::StandardKey key) |
Sets the triggers to those matching the standard key key. | |
void | setKeys (const QList< QKeySequence > &keys) |
Sets keys as the list of key sequences that trigger the shortcut. | |
QList< QKeySequence > | keys () const |
Returns the list of key sequences which trigger this shortcut. | |
void | setEnabled (bool enable) |
bool | isEnabled () const |
void | setContext (Qt::ShortcutContext context) |
Qt::ShortcutContext | context () const |
void | setAutoRepeat (bool on) |
bool | autoRepeat () const |
void | setWhatsThis (const QString &text) |
Sets the shortcut's "What's This?" help text. | |
QString | whatsThis () const |
Returns the shortcut's "What's This?" help text. | |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T > | |
T | findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
T | findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Protected Member Functions | |
bool | event (QEvent *e) override |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
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 | |
bool | enabled |
whether the shortcut is enabled | |
bool | autoRepeat |
whether the shortcut can auto repeat | |
Qt::ShortcutContext | context |
the context in which the shortcut is valid | |
Properties inherited from QObject | |
QString | objectName |
the name of this object | |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Related Symbols inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
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 18 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 178 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 205 of file qshortcut.cpp.
|
inline |
Definition at line 75 of file qshortcut.h.
|
inline |
Definition at line 83 of file qshortcut.h.
|
inline |
Definition at line 92 of file qshortcut.h.
|
inline |
Definition at line 102 of file qshortcut.h.
|
inline |
Definition at line 115 of file qshortcut.h.
|
inline |
Definition at line 123 of file qshortcut.h.
|
inline |
Definition at line 132 of file qshortcut.h.
|
inline |
Definition at line 142 of file qshortcut.h.
QShortcut::~QShortcut | ( | ) |
Destroys the shortcut.
Definition at line 336 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 495 of file qshortcut.cpp.
Qt::ShortcutContext QShortcut::context | ( | ) | const |
Definition at line 469 of file qshortcut.cpp.
Referenced by testing.tools.safetynet_job.JobRun::_BuildRunMetadata(), testing.tools.safetynet_job.JobRun::_IncrementalRun(), testing.tools.safetynet_job.JobRun::_WriteCheckpoint(), testing.tools.safetynet_job.JobRun::_WriteRawJson(), and testing.tools.safetynet_job.JobRun::Run().
|
overrideprotectedvirtual |
Reimplemented from QObject.
Definition at line 561 of file qshortcut.cpp.
bool QShortcut::isEnabled | ( | ) | const |
Definition at line 441 of file qshortcut.cpp.
QKeySequence QShortcut::key | ( | ) | const |
Definition at line 364 of file qshortcut.cpp.
QList< QKeySequence > QShortcut::keys | ( | ) | const |
Returns the list of key sequences which trigger this shortcut.
Definition at line 409 of file qshortcut.cpp.
void QShortcut::setAutoRepeat | ( | bool | on | ) |
Definition at line 484 of file qshortcut.cpp.
void QShortcut::setContext | ( | Qt::ShortcutContext | context | ) |
Definition at line 459 of file qshortcut.cpp.
void QShortcut::setEnabled | ( | bool | enable | ) |
Definition at line 430 of file qshortcut.cpp.
void QShortcut::setKey | ( | const QKeySequence & | key | ) |
Definition at line 356 of file qshortcut.cpp.
void QShortcut::setKeys | ( | const QList< QKeySequence > & | keys | ) |
Sets keys as the list of key sequences that trigger the shortcut.
Definition at line 380 of file qshortcut.cpp.
void QShortcut::setKeys | ( | QKeySequence::StandardKey | key | ) |
Sets the triggers to those matching the standard key key.
Definition at line 397 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 518 of file qshortcut.cpp.
QString QShortcut::whatsThis | ( | ) | const |
Returns the shortcut's "What's This?" help text.
Definition at line 529 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 24 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 25 of file qshortcut.h.
Referenced by testing.tools.safetynet_job.JobRun::_BuildRunMetadata(), testing.tools.safetynet_job.JobRun::_IncrementalRun(), testing.tools.safetynet_job.JobRun::_WriteCheckpoint(), testing.tools.safetynet_job.JobRun::_WriteRawJson(), and testing.tools.safetynet_job.JobRun::Run().
|
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 23 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 22 of file qshortcut.h.