Struct qt_gui::QKeySequence
source · #[repr(C)]pub struct QKeySequence { /* private fields */ }
Expand description
The QKeySequence class encapsulates a key sequence as used by shortcuts.
C++ class: QKeySequence
.
The QKeySequence class encapsulates a key sequence as used by shortcuts.
In its most common form, a key sequence describes a combination of keys that must be used together to perform some action. Key sequences are used with QAction objects to specify which keyboard shortcuts can be used to trigger actions.
Key sequences can be constructed for use as keyboard shortcuts in three different ways:
- For standard shortcuts, a standard key can be used to request the platform-specific key sequence associated with each shortcut.
- For custom shortcuts, human-readable strings such as "Ctrl+X" can be used, and these can be translated into the appropriate shortcuts for users of different languages. Translations are made in the "QShortcut" context.
- For hard-coded shortcuts, integer key codes can be specified with a combination of values defined by the Qt::Key and Qt::Modifier enum values. Each key code consists of a single Qt::Key value and zero or more modifiers, such as Qt::SHIFT, Qt::CTRL, Qt::ALT and Qt::META.
For example, Ctrl P might be a sequence used as a shortcut for printing a document, and can be specified in any of the following ways:
QKeySequence(QKeySequence::Print); QKeySequence(tr(“Ctrl+P”)); QKeySequence(tr(“Ctrl+p”)); QKeySequence(Qt::CTRL + Qt::Key_P);
Note that, for letters, the case used in the specification string does not matter. In the above examples, the user does not need to hold down the Shift key to activate a shortcut specified with "Ctrl+P". However, for other keys, the use of Shift as an unspecified extra modifier key can lead to confusion for users of an application whose keyboards have different layouts to those used by the developers. See the Keyboard Layout Issues section below for more details.
It is preferable to use standard shortcuts where possible. When creating key sequences for non-standard shortcuts, you should use human-readable strings in preference to hard-coded integer values.
QKeySequence objects can be cast to a QString to obtain a human-readable translated version of the sequence. Similarly, the toString() function produces human-readable strings for use in menus. On macOS, the appropriate symbols are used to describe keyboard shortcuts using special keys on the Macintosh keyboard.
An alternative way to specify hard-coded key codes is to use the Unicode code point of the character; for example, 'A' gives the same key sequence as Qt::Key_A.
Note: On macOS, references to "Ctrl", Qt::CTRL, Qt::Key_Control and Qt::ControlModifier correspond to the Command keys on the Macintosh keyboard, and references to "Meta", Qt::META, Qt::Key_Meta and Qt::MetaModifier correspond to the Control keys. Developers on macOS can use the same shortcut descriptions across all platforms, and their applications will automatically work as expected on macOS.
Implementations§
source§impl QKeySequence
impl QKeySequence
sourcepub unsafe fn copy_from(
&self,
other: impl CastInto<Ref<QKeySequence>>
) -> Ref<QKeySequence>
pub unsafe fn copy_from( &self, other: impl CastInto<Ref<QKeySequence>> ) -> Ref<QKeySequence>
Assignment operator. Assigns the other key sequence to this object.
Calls C++ function: QKeySequence& QKeySequence::operator=(const QKeySequence& other)
.
Assignment operator. Assigns the other key sequence to this object.
sourcepub unsafe fn count(&self) -> c_int
pub unsafe fn count(&self) -> c_int
Returns the number of keys in the key sequence. The maximum is 4.
Calls C++ function: int QKeySequence::count() const
.
Returns the number of keys in the key sequence. The maximum is 4.
sourcepub unsafe fn from_string_2a(
str: impl CastInto<Ref<QString>>,
format: SequenceFormat
) -> CppBox<QKeySequence>
pub unsafe fn from_string_2a( str: impl CastInto<Ref<QString>>, format: SequenceFormat ) -> CppBox<QKeySequence>
Return a QKeySequence from the string str based on format.
Calls C++ function: static QKeySequence QKeySequence::fromString(const QString& str, QKeySequence::SequenceFormat format = …)
.
Return a QKeySequence from the string str based on format.
This function was introduced in Qt 4.1.
See also toString().
sourcepub unsafe fn from_string_1a(
str: impl CastInto<Ref<QString>>
) -> CppBox<QKeySequence>
pub unsafe fn from_string_1a( str: impl CastInto<Ref<QString>> ) -> CppBox<QKeySequence>
Return a QKeySequence from the string str based on format.
Calls C++ function: static QKeySequence QKeySequence::fromString(const QString& str)
.
Return a QKeySequence from the string str based on format.
This function was introduced in Qt 4.1.
See also toString().
sourcepub unsafe fn index(&self, i: c_uint) -> c_int
pub unsafe fn index(&self, i: c_uint) -> c_int
Returns a reference to the element at position index in the key sequence. This can only be used to read an element.
Calls C++ function: int QKeySequence::operator[](unsigned int i) const
.
Returns a reference to the element at position index in the key sequence. This can only be used to read an element.
sourcepub unsafe fn is_detached(&self) -> bool
pub unsafe fn is_detached(&self) -> bool
Calls C++ function: bool QKeySequence::isDetached() const
.
sourcepub unsafe fn is_empty(&self) -> bool
pub unsafe fn is_empty(&self) -> bool
Returns true
if the key sequence is empty; otherwise returns false.
Calls C++ function: bool QKeySequence::isEmpty() const
.
Returns true
if the key sequence is empty; otherwise returns false.
sourcepub unsafe fn key_bindings(key: StandardKey) -> CppBox<QListOfQKeySequence>
pub unsafe fn key_bindings(key: StandardKey) -> CppBox<QListOfQKeySequence>
Returns a list of key bindings for the given key. The result of calling this function will vary based on the target platform. The first element of the list indicates the primary shortcut for the given platform. If the result contains more than one result, these can be considered alternative shortcuts on the same platform for the given key.
Calls C++ function: static QList<QKeySequence> QKeySequence::keyBindings(QKeySequence::StandardKey key)
.
Returns a list of key bindings for the given key. The result of calling this function will vary based on the target platform. The first element of the list indicates the primary shortcut for the given platform. If the result contains more than one result, these can be considered alternative shortcuts on the same platform for the given key.
This function was introduced in Qt 4.2.
sourcepub unsafe fn list_from_string_2a(
str: impl CastInto<Ref<QString>>,
format: SequenceFormat
) -> CppBox<QListOfQKeySequence>
pub unsafe fn list_from_string_2a( str: impl CastInto<Ref<QString>>, format: SequenceFormat ) -> CppBox<QListOfQKeySequence>
Return a list of QKeySequence from the string str based on format.
Calls C++ function: static QList<QKeySequence> QKeySequence::listFromString(const QString& str, QKeySequence::SequenceFormat format = …)
.
Return a list of QKeySequence from the string str based on format.
This function was introduced in Qt 5.1.
See also fromString() and listToString().
sourcepub unsafe fn list_from_string_1a(
str: impl CastInto<Ref<QString>>
) -> CppBox<QListOfQKeySequence>
pub unsafe fn list_from_string_1a( str: impl CastInto<Ref<QString>> ) -> CppBox<QListOfQKeySequence>
Return a list of QKeySequence from the string str based on format.
Calls C++ function: static QList<QKeySequence> QKeySequence::listFromString(const QString& str)
.
Return a list of QKeySequence from the string str based on format.
This function was introduced in Qt 5.1.
See also fromString() and listToString().
sourcepub unsafe fn list_to_string_2a(
list: impl CastInto<Ref<QListOfQKeySequence>>,
format: SequenceFormat
) -> CppBox<QString>
pub unsafe fn list_to_string_2a( list: impl CastInto<Ref<QListOfQKeySequence>>, format: SequenceFormat ) -> CppBox<QString>
Return a string representation of list based on format.
Calls C++ function: static QString QKeySequence::listToString(const QList<QKeySequence>& list, QKeySequence::SequenceFormat format = …)
.
Return a string representation of list based on format.
This function was introduced in Qt 5.1.
See also toString() and listFromString().
sourcepub unsafe fn list_to_string_1a(
list: impl CastInto<Ref<QListOfQKeySequence>>
) -> CppBox<QString>
pub unsafe fn list_to_string_1a( list: impl CastInto<Ref<QListOfQKeySequence>> ) -> CppBox<QString>
Return a string representation of list based on format.
Calls C++ function: static QString QKeySequence::listToString(const QList<QKeySequence>& list)
.
Return a string representation of list based on format.
This function was introduced in Qt 5.1.
See also toString() and listFromString().
sourcepub unsafe fn matches(
&self,
seq: impl CastInto<Ref<QKeySequence>>
) -> SequenceMatch
pub unsafe fn matches( &self, seq: impl CastInto<Ref<QKeySequence>> ) -> SequenceMatch
Matches the sequence with seq. Returns ExactMatch if successful, PartialMatch if seq matches incompletely, and NoMatch if the sequences have nothing in common. Returns NoMatch if seq is shorter.
Calls C++ function: QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence& seq) const
.
Matches the sequence with seq. Returns ExactMatch if successful, PartialMatch if seq matches incompletely, and NoMatch if the sequences have nothing in common. Returns NoMatch if seq is shorter.
sourcepub unsafe fn mnemonic(
text: impl CastInto<Ref<QString>>
) -> CppBox<QKeySequence>
pub unsafe fn mnemonic( text: impl CastInto<Ref<QString>> ) -> CppBox<QKeySequence>
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics are found.
Calls C++ function: static QKeySequence QKeySequence::mnemonic(const QString& text)
.
Returns the shortcut key sequence for the mnemonic in text, or an empty key sequence if no mnemonics are found.
For example, mnemonic("E&xit") returns Qt::ALT+Qt::Key_X
, mnemonic("&Quit") returns ALT+Key_Q
, and mnemonic("Quit") returns an empty QKeySequence.
We provide a list of common mnemonics in English. At the time of writing, Microsoft and Open Group do not appear to have issued equivalent recommendations for other languages.
sourcepub unsafe fn new() -> CppBox<QKeySequence>
pub unsafe fn new() -> CppBox<QKeySequence>
Constructs an empty key sequence.
Calls C++ function: [constructor] void QKeySequence::QKeySequence()
.
Constructs an empty key sequence.
sourcepub unsafe fn from_q_string_sequence_format(
key: impl CastInto<Ref<QString>>,
format: SequenceFormat
) -> CppBox<QKeySequence>
pub unsafe fn from_q_string_sequence_format( key: impl CastInto<Ref<QString>>, format: SequenceFormat ) -> CppBox<QKeySequence>
Creates a key sequence from the key string, based on format.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(const QString& key, QKeySequence::SequenceFormat format = …)
.
Creates a key sequence from the key string, based on format.
For example "Ctrl+O" gives CTRL+'O'. The strings "Ctrl", "Shift", "Alt" and "Meta" are recognized, as well as their translated equivalents in the "QShortcut" context (using QObject::tr()).
Up to four key codes may be entered by separating them with commas, e.g. "Alt+X,Ctrl+S,Q".
This constructor is typically used with tr(), so that shortcut keys can be replaced in translations:
QMenu *file = new QMenu(this); file->addAction(tr(“&Open…”), this, SLOT(open()), QKeySequence(tr(“Ctrl+O”, “File|Open”)));
Note the "File|Open" translator comment. It is by no means necessary, but it provides some context for the human translator.
sourcepub unsafe fn from_4_int(
k1: c_int,
k2: c_int,
k3: c_int,
k4: c_int
) -> CppBox<QKeySequence>
pub unsafe fn from_4_int( k1: c_int, k2: c_int, k3: c_int, k4: c_int ) -> CppBox<QKeySequence>
Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(int k1, int k2 = …, int k3 = …, int k4 = …)
.
sourcepub unsafe fn from_standard_key(key: StandardKey) -> CppBox<QKeySequence>
pub unsafe fn from_standard_key(key: StandardKey) -> CppBox<QKeySequence>
Constructs a QKeySequence object for the given key. The result will depend on the currently running platform.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(QKeySequence::StandardKey key)
.
Constructs a QKeySequence object for the given key. The result will depend on the currently running platform.
The resulting object will be based on the first element in the list of key bindings for the key.
This function was introduced in Qt 4.2.
sourcepub unsafe fn from_q_string(
key: impl CastInto<Ref<QString>>
) -> CppBox<QKeySequence>
pub unsafe fn from_q_string( key: impl CastInto<Ref<QString>> ) -> CppBox<QKeySequence>
Creates a key sequence from the key string, based on format.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(const QString& key)
.
Creates a key sequence from the key string, based on format.
For example "Ctrl+O" gives CTRL+'O'. The strings "Ctrl", "Shift", "Alt" and "Meta" are recognized, as well as their translated equivalents in the "QShortcut" context (using QObject::tr()).
Up to four key codes may be entered by separating them with commas, e.g. "Alt+X,Ctrl+S,Q".
This constructor is typically used with tr(), so that shortcut keys can be replaced in translations:
QMenu *file = new QMenu(this); file->addAction(tr(“&Open…”), this, SLOT(open()), QKeySequence(tr(“Ctrl+O”, “File|Open”)));
Note the "File|Open" translator comment. It is by no means necessary, but it provides some context for the human translator.
sourcepub unsafe fn from_3_int(
k1: c_int,
k2: c_int,
k3: c_int
) -> CppBox<QKeySequence>
pub unsafe fn from_3_int( k1: c_int, k2: c_int, k3: c_int ) -> CppBox<QKeySequence>
Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(int k1, int k2 = …, int k3 = …)
.
sourcepub unsafe fn from_2_int(k1: c_int, k2: c_int) -> CppBox<QKeySequence>
pub unsafe fn from_2_int(k1: c_int, k2: c_int) -> CppBox<QKeySequence>
Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(int k1, int k2 = …)
.
sourcepub unsafe fn from_int(k1: c_int) -> CppBox<QKeySequence>
pub unsafe fn from_int(k1: c_int) -> CppBox<QKeySequence>
Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(int k1)
.
sourcepub unsafe fn new_copy(
ks: impl CastInto<Ref<QKeySequence>>
) -> CppBox<QKeySequence>
pub unsafe fn new_copy( ks: impl CastInto<Ref<QKeySequence>> ) -> CppBox<QKeySequence>
Copy constructor. Makes a copy of keysequence.
Calls C++ function: [constructor] void QKeySequence::QKeySequence(const QKeySequence& ks)
.
Copy constructor. Makes a copy of keysequence.
sourcepub unsafe fn static_meta_object() -> Ref<QMetaObject>
pub unsafe fn static_meta_object() -> Ref<QMetaObject>
Returns a reference to the staticMetaObject
field.
sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QKeySequence>>)
pub unsafe fn swap(&self, other: impl CastInto<Ref<QKeySequence>>)
Swaps key sequence other with this key sequence. This operation is very fast and never fails.
Calls C++ function: void QKeySequence::swap(QKeySequence& other)
.
Swaps key sequence other with this key sequence. This operation is very fast and never fails.
This function was introduced in Qt 4.8.
sourcepub unsafe fn to_q_variant(&self) -> CppBox<QVariant>
pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>
sourcepub unsafe fn to_string_1a(&self, format: SequenceFormat) -> CppBox<QString>
pub unsafe fn to_string_1a(&self, format: SequenceFormat) -> CppBox<QString>
Return a string representation of the key sequence, based on format.
Calls C++ function: QString QKeySequence::toString(QKeySequence::SequenceFormat format = …) const
.
Return a string representation of the key sequence, based on format.
For example, the value Qt::CTRL+Qt::Key_O results in "Ctrl+O". If the key sequence has multiple key codes, each is separated by commas in the string returned, such as "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are translated using QObject::tr() in the "QShortcut" context.
If the key sequence has no keys, an empty string is returned.
On macOS, the string returned resembles the sequence that is shown in the menu bar if format is QKeySequence::NativeText; otherwise, the string uses the "portable" format, suitable for writing to a file.
This function was introduced in Qt 4.1.
See also fromString().
sourcepub unsafe fn to_string_0a(&self) -> CppBox<QString>
pub unsafe fn to_string_0a(&self) -> CppBox<QString>
Return a string representation of the key sequence, based on format.
Calls C++ function: QString QKeySequence::toString() const
.
Return a string representation of the key sequence, based on format.
For example, the value Qt::CTRL+Qt::Key_O results in "Ctrl+O". If the key sequence has multiple key codes, each is separated by commas in the string returned, such as "Alt+X, Ctrl+Y, Z". The strings, "Ctrl", "Shift", etc. are translated using QObject::tr() in the "QShortcut" context.
If the key sequence has no keys, an empty string is returned.
On macOS, the string returned resembles the sequence that is shown in the menu bar if format is QKeySequence::NativeText; otherwise, the string uses the "portable" format, suitable for writing to a file.
This function was introduced in Qt 4.1.
See also fromString().
Trait Implementations§
source§impl CppDeletable for QKeySequence
impl CppDeletable for QKeySequence
source§impl Ge<Ref<QKeySequence>> for QKeySequence
impl Ge<Ref<QKeySequence>> for QKeySequence
source§unsafe fn ge(&self, other: &Ref<QKeySequence>) -> bool
unsafe fn ge(&self, other: &Ref<QKeySequence>) -> bool
Returns true
if this key sequence is larger or equal to the other key sequence; otherwise returns false
.
Calls C++ function: bool QKeySequence::operator>=(const QKeySequence& other) const
.
Returns true
if this key sequence is larger or equal to the other key sequence; otherwise returns false
.
See also operator==(), operator!=(), operator<(), operator>(), and operator<=().
source§impl Gt<Ref<QKeySequence>> for QKeySequence
impl Gt<Ref<QKeySequence>> for QKeySequence
source§unsafe fn gt(&self, other: &Ref<QKeySequence>) -> bool
unsafe fn gt(&self, other: &Ref<QKeySequence>) -> bool
Returns true
if this key sequence is larger than the other key sequence; otherwise returns false
.
Calls C++ function: bool QKeySequence::operator>(const QKeySequence& other) const
.
Returns true
if this key sequence is larger than the other key sequence; otherwise returns false
.
See also operator==(), operator!=(), operator<(), operator<=(), and operator>=().
source§impl Le<Ref<QKeySequence>> for QKeySequence
impl Le<Ref<QKeySequence>> for QKeySequence
source§unsafe fn le(&self, other: &Ref<QKeySequence>) -> bool
unsafe fn le(&self, other: &Ref<QKeySequence>) -> bool
Returns true
if this key sequence is smaller or equal to the other key sequence; otherwise returns false
.
Calls C++ function: bool QKeySequence::operator<=(const QKeySequence& other) const
.
Returns true
if this key sequence is smaller or equal to the other key sequence; otherwise returns false
.
See also operator==(), operator!=(), operator<(), operator>(), and operator>=().
source§impl Lt<Ref<QKeySequence>> for QKeySequence
impl Lt<Ref<QKeySequence>> for QKeySequence
source§unsafe fn lt(&self, ks: &Ref<QKeySequence>) -> bool
unsafe fn lt(&self, ks: &Ref<QKeySequence>) -> bool
Provides an arbitrary comparison of this key sequence and other key sequence. All that is guaranteed is that the operator returns false
if both key sequences are equal and that (ks1 < ks2) == !( ks2 < ks1) if the key sequences are not equal.
Calls C++ function: bool QKeySequence::operator<(const QKeySequence& ks) const
.
Provides an arbitrary comparison of this key sequence and other key sequence. All that is guaranteed is that the operator returns false
if both key sequences are equal and that (ks1 < ks2) == !( ks2 < ks1) if the key sequences are not equal.
This function is useful in some circumstances, for example if you want to use QKeySequence objects as keys in a QMap.
See also operator==(), operator!=(), operator>(), operator<=(), and operator>=().
source§impl PartialEq<Ref<QKeySequence>> for QKeySequence
impl PartialEq<Ref<QKeySequence>> for QKeySequence
source§fn eq(&self, other: &Ref<QKeySequence>) -> bool
fn eq(&self, other: &Ref<QKeySequence>) -> bool
Returns true
if this key sequence is equal to the other key sequence; otherwise returns false
.
Calls C++ function: bool QKeySequence::operator==(const QKeySequence& other) const
.
Returns true
if this key sequence is equal to the other key sequence; otherwise returns false
.