QKeySequence Class
The QKeySequence class encapsulates a key combination used by a shortcut. More…
| Header | #include <QKeySequence> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
List of all members, including inherited members
Public Types
| enum | StandardKey |
| enum | SequenceFormat |
| enum | SequenceMatch |
Public Functions
| QKeySequence() | |
| QKeySequence(const QString &key, SequenceFormat format = NativeText) | |
| QKeySequence(int k1) | |
| QKeySequence(StandardKey key) | |
| int | count() const |
| bool | isEmpty() const |
| QString | toString(SequenceFormat format = PortableText) const |
| SequenceMatch | matches(const QKeySequence &seq) const |
| int | operator[](uint index) const |
| bool | operator==(const QKeySequence &other) const |
| bool | operator!=(const QKeySequence &other) const |
| bool | operator<(const QKeySequence &other) const |
Static Public Members
| QKeySequence | fromString(const QString &str, SequenceFormat format = PortableText) |
| QList<QKeySequence> | keyBindings(StandardKey key) |
| QKeySequence | mnemonic(const QString &text) |
Detailed Description
A key sequence is a key with modifiers, such as Ctrl+S. It is written as a string, "Ctrl+Shift+S", as a number, Qt::CTRL | Qt::SHIFT | Qt::Key_S, or as one of the standard keys that a platform has for an action:
QAction *save = new QAction("Save", this);
save->setShortcut(QKeySequence::Save);
QAction *quit = new QAction("Quit", this);
quit->setShortcut(QKeySequence("Ctrl+Q"));
See also QAction::setShortcut().
Differences from Qt
A sequence is a single key with its modifiers: there are no sequences of several keys such as "Ctrl+X, Ctrl+C", so count() is 0 or 1 and matches() never returns PartialMatch. The key names are in English, and the list of standard keys is shorter and has the bindings of Linux only (keyBindings() has one binding for each key).
Member Type Documentation
enum QKeySequence::SequenceFormat
This enum says how a key sequence is written as a string.
| Constant | Description |
|---|---|
QKeySequence::NativeText | The way the platform writes it. On Linux this is the same as PortableText. |
QKeySequence::PortableText | The English names, such as "Ctrl+Shift+S", that do not depend on the platform. |
enum QKeySequence::SequenceMatch
This enum says how much of a sequence another one has.
| Constant | Description |
|---|---|
QKeySequence::NoMatch | The sequences are different. |
QKeySequence::PartialMatch | The first one is the start of the second one; this never happens, as a sequence is one key. |
QKeySequence::ExactMatch | The sequences are the same. |
enum QKeySequence::StandardKey
This enum names the key combinations that a platform has for common actions.
| Constant | Description |
|---|---|
QKeySequence::UnknownKey | No key. |
QKeySequence::HelpContents | Open the help: F1. |
QKeySequence::Open | Open a document: Ctrl+O. |
QKeySequence::Close | Close a document: Ctrl+W. |
QKeySequence::Save | Save a document: Ctrl+S. |
QKeySequence::New | Create a document: Ctrl+N. |
QKeySequence::Delete | Delete the selection: Del. |
QKeySequence::Cut | Cut the selection: Ctrl+X. |
QKeySequence::Copy | Copy the selection: Ctrl+C. |
QKeySequence::Paste | Paste from the clipboard: Ctrl+V. |
QKeySequence::Undo | Undo the last action: Ctrl+Z. |
QKeySequence::Redo | Redo the last undone action: Ctrl+Shift+Z. |
QKeySequence::Back | Go back: Alt+Left. |
QKeySequence::Forward | Go forward: Alt+Right. |
QKeySequence::Refresh | Refresh the view: F5. |
QKeySequence::ZoomIn | Zoom in: Ctrl++. |
QKeySequence::ZoomOut | Zoom out: Ctrl+-. |
QKeySequence::Print | Print: Ctrl+P. |
QKeySequence::Find | Find: Ctrl+F. |
QKeySequence::FindNext | Find the next match: F3. |
QKeySequence::FindPrevious | Find the previous match: Shift+F3. |
QKeySequence::Replace | Find and replace: Ctrl+H. |
QKeySequence::SelectAll | Select everything: Ctrl+A. |
QKeySequence::Quit | Quit the application: Ctrl+Q. |
QKeySequence::SaveAs | Save a document with another name: Ctrl+Shift+S. |
QKeySequence::Cancel | Cancel the operation: Esc. |
QKeySequence::FullScreen | Switch to full screen: F11. |
QKeySequence::NextChild | Go to the next tab or window: Ctrl+Tab. |
QKeySequence::PreviousChild | Go to the previous tab or window: Ctrl+Shift+Backtab. |
Member Function Documentation
QKeySequence::QKeySequence()
Constructs an empty key sequence.
QKeySequence::QKeySequence(const QString &key, SequenceFormat format = NativeText)
Constructs a key sequence from the string key, such as "Ctrl+O", in the given format. The sequence is empty if the string is not a key combination.
See also fromString().
QKeySequence::QKeySequence(int k1)
Constructs a key sequence from k1, a key with its modifiers, as in Qt::CTRL | Qt::Key_O.
QKeySequence::QKeySequence(StandardKey key)
Constructs the key sequence that the platform has for the standard key key; it is empty for UnknownKey.
See also keyBindings().
int QKeySequence::count() const
Returns the number of keys in the sequence: 1, or 0 if it is empty.
QKeySequence QKeySequence::fromString(const QString &str, SequenceFormat format = PortableText)
Returns the key sequence that the string str has, in the given format. The modifiers Ctrl, Shift, Alt and Meta, in any case and in any order, are joined to a key by +. The key is a character, F1 to F12, or a name such as Esc, Del, Return, PgUp or Space. An empty sequence is returned for a string that is not a key combination.
See also toString().
bool QKeySequence::isEmpty() const
Returns true if the sequence has no key; otherwise returns false.
QList<QKeySequence> QKeySequence::keyBindings(StandardKey key)
Returns the key sequences that the platform has for the standard key key: one on Linux, and none for UnknownKey.
SequenceMatch QKeySequence::matches(const QKeySequence &seq) const
Returns ExactMatch if seq is the same sequence as this one, and NoMatch if it is not; two empty sequences do not match.
QKeySequence QKeySequence::mnemonic(const QString &text)
Returns the mnemonic of text as a key sequence: Alt and the letter that follows the first &, as Alt+F for "&File". A && is an ampersand and not a mnemonic. The sequence is empty if there is no mnemonic.
bool QKeySequence::operator!=(const QKeySequence &other) const
Returns true if this sequence and other are different key combinations; otherwise returns false.
bool QKeySequence::operator<(const QKeySequence &other) const
Returns true if this sequence sorts before other, which has no meaning but an order; otherwise returns false.
bool QKeySequence::operator==(const QKeySequence &other) const
Returns true if this sequence and other are the same key combination; otherwise returns false.
int QKeySequence::operator[](uint index) const
Returns the key with its modifiers at index, which is 0 for the one key that there is; 0 for any other index.
QString QKeySequence::toString(SequenceFormat format = PortableText) const
Returns the sequence as a string in the given format, such as "Ctrl+Shift+S", or an empty string for an empty sequence.
See also fromString().