Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qshortcut.h
Go to the documentation of this file.
1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSHORTCUT_H
5#define QSHORTCUT_H
6
7#include <QtGui/qtguiglobal.h>
8#include <QtGui/qkeysequence.h>
9#include <QtCore/qobject.h>
10
12
14
16class QWindow;
17
18class Q_GUI_EXPORT QShortcut : public QObject
19{
21 Q_DECLARE_PRIVATE(QShortcut)
23 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
24 Q_PROPERTY(bool autoRepeat READ autoRepeat WRITE setAutoRepeat)
25 Q_PROPERTY(Qt::ShortcutContext context READ context WRITE setContext)
26public:
27 explicit QShortcut(QObject *parent);
29 const char *member = nullptr, const char *ambiguousMember = nullptr,
30 Qt::ShortcutContext context = Qt::WindowShortcut);
31 explicit QShortcut(QKeySequence::StandardKey key, QObject *parent,
32 const char *member = nullptr, const char *ambiguousMember = nullptr,
33 Qt::ShortcutContext context = Qt::WindowShortcut);
34
35#ifdef Q_QDOC
36 template<typename Functor>
37 QShortcut(const QKeySequence &key, QObject *parent,
38 Functor functor,
39 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
40 template<typename Functor>
41 QShortcut(const QKeySequence &key, QObject *parent,
42 const QObject *context, Functor functor,
43 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
44 template<typename Functor, typename FunctorAmbiguous>
45 QShortcut(const QKeySequence &key, QObject *parent,
46 const QObject *context1, Functor functor,
47 FunctorAmbiguous functorAmbiguous,
48 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
49 template<typename Functor, typename FunctorAmbiguous>
50 QShortcut(const QKeySequence &key, QObject *parent,
51 const QObject *context1, Functor functor,
52 const QObject *context2, FunctorAmbiguous functorAmbiguous,
53 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
54
55 template<typename Functor>
57 Functor functor,
58 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
59 template<typename Functor>
61 const QObject *context, Functor functor,
62 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
63 template<typename Functor, typename FunctorAmbiguous>
65 const QObject *context1, Functor functor,
66 FunctorAmbiguous functorAmbiguous,
67 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
68 template<typename Functor, typename FunctorAmbiguous>
70 const QObject *context1, Functor functor,
71 const QObject *context2, FunctorAmbiguous functorAmbiguous,
72 Qt::ShortcutContext shortcutContext = Qt::WindowShortcut);
73#else
74 template<typename Func1>
76 Func1 slot1,
78 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
79 {
80 connect(this, &QShortcut::activated, std::move(slot1));
81 }
82 template<class Obj1, typename Func1>
84 const Obj1 *object1, Func1 slot1,
87 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
88 {
89 connect(this, &QShortcut::activated, object1, std::move(slot1));
90 }
91 template<class Obj1, typename Func1, typename Func2>
93 const Obj1 *object1, Func1 slot1, Func2 slot2,
96 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
97 {
98 connect(this, &QShortcut::activated, object1, std::move(slot1));
99 connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2));
100 }
101 template<class Obj1, typename Func1, class Obj2, typename Func2>
103 const Obj1 *object1, Func1 slot1,
104 const Obj2 *object2, Func2 slot2,
108 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
109 {
110 connect(this, &QShortcut::activated, object1, std::move(slot1));
111 connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
112 }
113
114 template<typename Func1>
116 Func1 slot1,
118 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
119 {
120 connect(this, &QShortcut::activated, std::move(slot1));
121 }
122 template<class Obj1, typename Func1>
124 const Obj1 *object1, Func1 slot1,
127 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
128 {
129 connect(this, &QShortcut::activated, object1, std::move(slot1));
130 }
131 template<class Obj1, typename Func1, typename Func2>
133 const Obj1 *object1, Func1 slot1, Func2 slot2,
136 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
137 {
138 connect(this, &QShortcut::activated, object1, std::move(slot1));
139 connect(this, &QShortcut::activatedAmbiguously, object1, std::move(slot2));
140 }
141 template<class Obj1, typename Func1, class Obj2, typename Func2>
143 const Obj1 *object1, Func1 slot1,
144 const Obj2 *object2, Func2 slot2,
148 : QShortcut(key, parent, static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), context)
149 {
150 connect(this, &QShortcut::activated, object1, std::move(slot1));
151 connect(this, &QShortcut::activatedAmbiguously, object2, std::move(slot2));
152 }
153#endif
154
155 ~QShortcut();
156
157 void setKey(const QKeySequence& key);
158 QKeySequence key() const;
159 void setKeys(QKeySequence::StandardKey key);
160 void setKeys(const QList<QKeySequence> &keys);
161 QList<QKeySequence> keys() const;
162
163 void setEnabled(bool enable);
164 bool isEnabled() const;
165
166 void setContext(Qt::ShortcutContext context);
168
169 void setAutoRepeat(bool on);
170 bool autoRepeat() const;
171
172#if QT_DEPRECATED_SINCE(6,0)
173 QT_DEPRECATED_VERSION_6_0 int id() const;
174#endif
175
176 void setWhatsThis(const QString &text);
177 QString whatsThis() const;
178
179#if QT_DEPRECATED_SINCE(6,0)
180#ifdef Q_QDOC
181 QWidget *parentWidget() const;
182#else
183 template<typename T = QWidget*>
184 QT_DEPRECATED_VERSION_X_6_0("Use parent() and qobject_cast instead")
185 inline T parentWidget() const
186 { return static_cast<T>(QObject::parent()); }
187#endif
188#endif
189
191 void activated();
193
194protected:
195 bool event(QEvent *e) override;
196};
197
199
200#endif // QSHORTCUT_H
\inmodule QtCore
Definition qcoreevent.h:45
The QKeySequence class encapsulates a key sequence as used by shortcuts.
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
The QShortcut class is used to create keyboard shortcuts.
Definition qshortcut.h:19
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)
Definition qshortcut.h:83
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)
Definition qshortcut.h:92
void activatedAmbiguously()
When a key sequence is being typed at the keyboard, it is said to be ambiguous as long as it matches ...
QShortcut(QKeySequence::StandardKey key, QObject *parent, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut)
Definition qshortcut.h:115
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)
Definition qshortcut.h:132
QShortcut(const QKeySequence &key, QObject *parent, Func1 slot1, Qt::ShortcutContext context=Qt::WindowShortcut)
Definition qshortcut.h:75
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)
Definition qshortcut.h:123
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)
Definition qshortcut.h:102
void activated()
This signal is emitted when the user types the shortcut's key sequence.
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)
Definition qshortcut.h:142
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
\inmodule QtGui
Definition qwindow.h:63
QString text
Combined button and popup list for selecting options.
Definition qcompare.h:63
ShortcutContext
@ WindowShortcut
static void * context
GLuint64 key
GLenum GLuint id
[7]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLboolean enable
struct _cl_event * event
decorationRoleName toolTipRoleName setWhatsThis
#define QT_REQUIRE_CONFIG(feature)
#define QT_DEPRECATED_VERSION_X_6_0(text)
#define QT_DEPRECATED_VERSION_6_0
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SIGNALS
#define explicit
QStringList keys
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
QObject::connect nullptr
setKey(0)
[0]