6.0.0-rc4Source

QKeySequence Class

The QKeySequence class encapsulates a key combination used by a shortcut. More…

Header#include <QKeySequence>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QKeySequence()
QKeySequence(const QString &key, SequenceFormat format = NativeText)
QKeySequence(int k1)
QKeySequence(StandardKey key)
intcount() const
boolisEmpty() const
QStringtoString(SequenceFormat format = PortableText) const
SequenceMatchmatches(const QKeySequence &seq) const
intoperator[](uint index) const
booloperator==(const QKeySequence &other) const
booloperator!=(const QKeySequence &other) const
booloperator<(const QKeySequence &other) const

Static Public Members

QKeySequencefromString(const QString &str, SequenceFormat format = PortableText)
QList<QKeySequence>keyBindings(StandardKey key)
QKeySequencemnemonic(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.

ConstantDescription
QKeySequence::NativeTextThe way the platform writes it. On Linux this is the same as PortableText.
QKeySequence::PortableTextThe 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.

ConstantDescription
QKeySequence::NoMatchThe sequences are different.
QKeySequence::PartialMatchThe first one is the start of the second one; this never happens, as a sequence is one key.
QKeySequence::ExactMatchThe sequences are the same.

enum QKeySequence::StandardKey

This enum names the key combinations that a platform has for common actions.

ConstantDescription
QKeySequence::UnknownKeyNo key.
QKeySequence::HelpContentsOpen the help: F1.
QKeySequence::OpenOpen a document: Ctrl+O.
QKeySequence::CloseClose a document: Ctrl+W.
QKeySequence::SaveSave a document: Ctrl+S.
QKeySequence::NewCreate a document: Ctrl+N.
QKeySequence::DeleteDelete the selection: Del.
QKeySequence::CutCut the selection: Ctrl+X.
QKeySequence::CopyCopy the selection: Ctrl+C.
QKeySequence::PastePaste from the clipboard: Ctrl+V.
QKeySequence::UndoUndo the last action: Ctrl+Z.
QKeySequence::RedoRedo the last undone action: Ctrl+Shift+Z.
QKeySequence::BackGo back: Alt+Left.
QKeySequence::ForwardGo forward: Alt+Right.
QKeySequence::RefreshRefresh the view: F5.
QKeySequence::ZoomInZoom in: Ctrl++.
QKeySequence::ZoomOutZoom out: Ctrl+-.
QKeySequence::PrintPrint: Ctrl+P.
QKeySequence::FindFind: Ctrl+F.
QKeySequence::FindNextFind the next match: F3.
QKeySequence::FindPreviousFind the previous match: Shift+F3.
QKeySequence::ReplaceFind and replace: Ctrl+H.
QKeySequence::SelectAllSelect everything: Ctrl+A.
QKeySequence::QuitQuit the application: Ctrl+Q.
QKeySequence::SaveAsSave a document with another name: Ctrl+Shift+S.
QKeySequence::CancelCancel the operation: Esc.
QKeySequence::FullScreenSwitch to full screen: F11.
QKeySequence::NextChildGo to the next tab or window: Ctrl+Tab.
QKeySequence::PreviousChildGo 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.

[static] 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.

[static] 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.

[static] 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().