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.

C++ documentation:

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

source

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).

C++ documentation:

Assignment operator. Assigns the other key sequence to this object.

source

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.

C++ documentation:

Returns the number of keys in the key sequence. The maximum is 4.

source

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 = …).

C++ documentation:

Return a QKeySequence from the string str based on format.

This function was introduced in Qt 4.1.

See also toString().

source

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).

C++ documentation:

Return a QKeySequence from the string str based on format.

This function was introduced in Qt 4.1.

See also toString().

source

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.

C++ documentation:

Returns a reference to the element at position index in the key sequence. This can only be used to read an element.

source

pub unsafe fn is_detached(&self) -> bool

Calls C++ function: bool QKeySequence::isDetached() const.

source

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.

C++ documentation:

Returns true if the key sequence is empty; otherwise returns false.

source

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).

C++ documentation:

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.

source

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 = …).

C++ documentation:

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().

source

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).

C++ documentation:

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().

source

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 = …).

C++ documentation:

Return a string representation of list based on format.

This function was introduced in Qt 5.1.

See also toString() and listFromString().

source

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).

C++ documentation:

Return a string representation of list based on format.

This function was introduced in Qt 5.1.

See also toString() and listFromString().

source

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.

C++ documentation:

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.

source

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).

C++ documentation:

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.

source

pub unsafe fn new() -> CppBox<QKeySequence>

Constructs an empty key sequence.

Calls C++ function: [constructor] void QKeySequence::QKeySequence().

C++ documentation:

Constructs an empty key sequence.

source

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 = …).

C++ documentation:

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.

source

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 = …).

C++ documentation:

Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.

The key codes are listed in Qt::Key and can be combined with modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL, Qt::ALT, or Qt::META.

source

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).

C++ documentation:

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.

source

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).

C++ documentation:

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.

source

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 = …).

C++ documentation:

Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.

The key codes are listed in Qt::Key and can be combined with modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL, Qt::ALT, or Qt::META.

source

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 = …).

C++ documentation:

Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.

The key codes are listed in Qt::Key and can be combined with modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL, Qt::ALT, or Qt::META.

source

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).

C++ documentation:

Constructs a key sequence with up to 4 keys k1, k2, k3 and k4.

The key codes are listed in Qt::Key and can be combined with modifiers (see Qt::Modifier) such as Qt::SHIFT, Qt::CTRL, Qt::ALT, or Qt::META.

source

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).

C++ documentation:

Copy constructor. Makes a copy of keysequence.

source

pub unsafe fn static_meta_object() -> Ref<QMetaObject>

Returns a reference to the staticMetaObject field.

source

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).

C++ documentation:

Swaps key sequence other with this key sequence. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

source

pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>

Returns the key sequence as a QVariant

Calls C++ function: QVariant QKeySequence::operator QVariant() const.

C++ documentation:

Returns the key sequence as a QVariant

source

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.

C++ documentation:

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().

source

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.

C++ documentation:

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

source§

unsafe fn delete(&self)

Destroys the key sequence.

Calls C++ function: [destructor] void QKeySequence::~QKeySequence().

C++ documentation:

Destroys the key sequence.

source§

impl Ge<Ref<QKeySequence>> for QKeySequence

source§

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.

C++ documentation:

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

source§

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.

C++ documentation:

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

source§

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.

C++ documentation:

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

source§

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.

C++ documentation:

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

source§

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.

C++ documentation:

Returns true if this key sequence is equal to the other key sequence; otherwise returns false.

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.