[][src]Struct qt_widgets::QShortcut

#[repr(C)]
pub struct QShortcut { /* fields omitted */ }

The QShortcut class is used to create keyboard shortcuts.

C++ class: QShortcut.

C++ documentation:

The QShortcut class is used to create keyboard shortcuts.

The QShortcut class provides a way of connecting keyboard shortcuts to Qt's signals and slots mechanism, so that objects can be informed when a shortcut is executed. The shortcut can be set up to contain all the key presses necessary to describe a keyboard shortcut, including the states of modifier keys such as Shift, Ctrl, and Alt.

On certain widgets, using '&' in front of a character will automatically create a mnemonic (a shortcut) for that character, e.g. "E&xit" will create the shortcut Alt+X (use '&&' to display an actual ampersand). The widget might consume and perform an action on a given shortcut. On X11 the ampersand will not be shown and the character will be underlined. On Windows, shortcuts are normally not displayed until the user presses the Alt key, but this is a setting the user can change. On Mac, shortcuts are disabled by default. Call qt_set_sequence_auto_mnemonic() to enable them. However, because mnemonic shortcuts do not fit in with Aqua's guidelines, Qt will not show the shortcut character underlined.

For applications that use menus, it may be more convenient to use the convenience functions provided in the QMenu class to assign keyboard shortcuts to menu items as they are created. Alternatively, shortcuts may be associated with other types of actions in the QAction class.

The simplest way to create a shortcut for a particular widget is to construct the shortcut with a key sequence. For example:

shortcut = new QShortcut(QKeySequence(tr("Ctrl+O", "File|Open")), parent);

When the user types the key sequence for a given shortcut, the shortcut's activated() signal is emitted. (In the case of ambiguity, the activatedAmbiguously() signal is emitted.) A shortcut is "listened for" by Qt's event loop when the shortcut's parent widget is receiving events.

A shortcut's key sequence can be set with setKey() and retrieved with key(). A shortcut can be enabled or disabled with setEnabled(), and can have "What's This?" help text set with setWhatsThis().

Methods

impl QShortcut[src]

pub fn activated(&self) -> Signal<()>[src]

This signal is emitted when the user types the shortcut's key sequence.

Returns a built-in Qt signal QShortcut::activated that can be passed to qt_core::Signal::connect.

C++ documentation:

This signal is emitted when the user types the shortcut's key sequence.

See also activatedAmbiguously().

pub fn activated_ambiguously(&self) -> Signal<()>[src]

When a key sequence is being typed at the keyboard, it is said to be ambiguous as long as it matches the start of more than one shortcut.

Returns a built-in Qt signal QShortcut::activatedAmbiguously that can be passed to qt_core::Signal::connect.

C++ documentation:

When a key sequence is being typed at the keyboard, it is said to be ambiguous as long as it matches the start of more than one shortcut.

When a shortcut's key sequence is completed, activatedAmbiguously() is emitted if the key sequence is still ambiguous (i.e., it is the start of one or more other shortcuts). The activated() signal is not emitted in this case.

See also activated().

pub unsafe fn auto_repeat(&self) -> bool[src]

This property holds whether the shortcut can auto repeat

Calls C++ function: bool QShortcut::autoRepeat() const.

C++ documentation:

This property holds whether the shortcut can auto repeat

If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.

This property was introduced in Qt 4.2.

Access functions:

bool autoRepeat() const
void setAutoRepeat(bool on)

pub unsafe fn context(&self) -> ShortcutContext[src]

This property holds the context in which the shortcut is valid

Calls C++ function: Qt::ShortcutContext QShortcut::context() const.

C++ documentation:

This property holds the context in which the shortcut is valid

A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is Qt::WindowShortcut, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.

By default, this property is set to Qt::WindowShortcut.

Access functions:

Qt::ShortcutContext context() const
void setContext(Qt::ShortcutContext context)

pub unsafe fn id(&self) -> c_int[src]

Returns the shortcut's ID.

Calls C++ function: int QShortcut::id() const.

C++ documentation:

Returns the shortcut's ID.

See also QShortcutEvent::shortcutId().

pub unsafe fn is_enabled(&self) -> bool[src]

This property holds whether the shortcut is enabled

Calls C++ function: bool QShortcut::isEnabled() const.

C++ documentation:

This property holds whether the shortcut is enabled

An enabled shortcut emits the activated() or activatedAmbiguously() signal when a QShortcutEvent occurs that matches the shortcut's key() sequence.

If the application is in WhatsThis mode the shortcut will not emit the signals, but will show the "What's This?" text instead.

By default, this property is true.

Access functions:

bool isEnabled() const
void setEnabled(bool enable)

See also whatsThis.

pub unsafe fn key(&self) -> CppBox<QKeySequence>[src]

This property holds the shortcut's key sequence

Calls C++ function: QKeySequence QShortcut::key() const.

C++ documentation:

This property holds the shortcut's key sequence

This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:

setKey(0); // no signal emitted setKey(QKeySequence()); // no signal emitted setKey(0x3b1); // Greek letter alpha setKey(Qt::Key_D); // 'd', e.g. to delete setKey('q'); // 'q', e.g. to quit setKey(Qt::CTRL + Qt::Key_P); // Ctrl+P, e.g. to print document setKey("Ctrl+P"); // Ctrl+P, e.g. to print document

By default, this property contains an empty key sequence.

Access functions:

QKeySequence key() const
void setKey(const QKeySequence &key)

pub unsafe fn meta_object(&self) -> Ptr<QMetaObject>[src]

Calls C++ function: virtual const QMetaObject* QShortcut::metaObject() const.

pub unsafe fn new_1a(
    parent: impl CastInto<MutPtr<QWidget>>
) -> CppBox<QShortcut>
[src]

Constructs a QShortcut object for the parent widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.

Calls C++ function: [constructor] void QShortcut::QShortcut(QWidget* parent).

C++ documentation:

Constructs a QShortcut object for the parent widget. Since no shortcut key sequence is specified, the shortcut will not emit any signals.

See also setKey().

pub unsafe fn new_5a(
    key: impl CastInto<Ref<QKeySequence>>,
    parent: impl CastInto<MutPtr<QWidget>>,
    member: impl CastInto<Ptr<c_char>>,
    ambiguous_member: impl CastInto<Ptr<c_char>>,
    context: ShortcutContext
) -> CppBox<QShortcut>
[src]

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

Calls C++ function: [constructor] void QShortcut::QShortcut(const QKeySequence& key, QWidget* parent, const char* member = …, const char* ambiguousMember = …, Qt::ShortcutContext context = …).

C++ documentation:

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

pub unsafe fn new_4a(
    key: impl CastInto<Ref<QKeySequence>>,
    parent: impl CastInto<MutPtr<QWidget>>,
    member: impl CastInto<Ptr<c_char>>,
    ambiguous_member: impl CastInto<Ptr<c_char>>
) -> CppBox<QShortcut>
[src]

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

Calls C++ function: [constructor] void QShortcut::QShortcut(const QKeySequence& key, QWidget* parent, const char* member = …, const char* ambiguousMember = …).

C++ documentation:

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

pub unsafe fn new_3a(
    key: impl CastInto<Ref<QKeySequence>>,
    parent: impl CastInto<MutPtr<QWidget>>,
    member: impl CastInto<Ptr<c_char>>
) -> CppBox<QShortcut>
[src]

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

Calls C++ function: [constructor] void QShortcut::QShortcut(const QKeySequence& key, QWidget* parent, const char* member = …).

C++ documentation:

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

pub unsafe fn new_2a(
    key: impl CastInto<Ref<QKeySequence>>,
    parent: impl CastInto<MutPtr<QWidget>>
) -> CppBox<QShortcut>
[src]

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

Calls C++ function: [constructor] void QShortcut::QShortcut(const QKeySequence& key, QWidget* parent).

C++ documentation:

Constructs a QShortcut object for the parent widget. The shortcut operates on its parent, listening for QShortcutEvents that match the key sequence. Depending on the ambiguity of the event, the shortcut will call the member function, or the ambiguousMember function, if the key press was in the shortcut's context.

pub unsafe fn parent_widget(&self) -> MutPtr<QWidget>[src]

Returns the shortcut's parent widget.

Calls C++ function: QWidget* QShortcut::parentWidget() const.

C++ documentation:

Returns the shortcut's parent widget.

pub unsafe fn qt_metacall(
    &mut self,
    arg1: Call,
    arg2: c_int,
    arg3: impl CastInto<MutPtr<*mut c_void>>
) -> c_int
[src]

Calls C++ function: virtual int QShortcut::qt_metacall(QMetaObject::Call arg1, int arg2, void** arg3).

pub unsafe fn qt_metacast(
    &mut self,
    arg1: impl CastInto<Ptr<c_char>>
) -> MutPtr<c_void>
[src]

Calls C++ function: virtual void* QShortcut::qt_metacast(const char* arg1).

pub unsafe fn set_auto_repeat(&mut self, on: bool)[src]

This property holds whether the shortcut can auto repeat

Calls C++ function: void QShortcut::setAutoRepeat(bool on).

C++ documentation:

This property holds whether the shortcut can auto repeat

If true, the shortcut will auto repeat when the keyboard shortcut combination is held down, provided that keyboard auto repeat is enabled on the system. The default value is true.

This property was introduced in Qt 4.2.

Access functions:

bool autoRepeat() const
void setAutoRepeat(bool on)

pub unsafe fn set_context(&mut self, context: ShortcutContext)[src]

This property holds the context in which the shortcut is valid

Calls C++ function: void QShortcut::setContext(Qt::ShortcutContext context).

C++ documentation:

This property holds the context in which the shortcut is valid

A shortcut's context decides in which circumstances a shortcut is allowed to be triggered. The normal context is Qt::WindowShortcut, which allows the shortcut to trigger if the parent (the widget containing the shortcut) is a subwidget of the active top-level window.

By default, this property is set to Qt::WindowShortcut.

Access functions:

Qt::ShortcutContext context() const
void setContext(Qt::ShortcutContext context)

pub unsafe fn set_enabled(&mut self, enable: bool)[src]

This property holds whether the shortcut is enabled

Calls C++ function: void QShortcut::setEnabled(bool enable).

C++ documentation:

This property holds whether the shortcut is enabled

An enabled shortcut emits the activated() or activatedAmbiguously() signal when a QShortcutEvent occurs that matches the shortcut's key() sequence.

If the application is in WhatsThis mode the shortcut will not emit the signals, but will show the "What's This?" text instead.

By default, this property is true.

Access functions:

bool isEnabled() const
void setEnabled(bool enable)

See also whatsThis.

pub unsafe fn set_key(&mut self, key: impl CastInto<Ref<QKeySequence>>)[src]

This property holds the shortcut's key sequence

Calls C++ function: void QShortcut::setKey(const QKeySequence& key).

C++ documentation:

This property holds the shortcut's key sequence

This is a key sequence with an optional combination of Shift, Ctrl, and Alt. The key sequence may be supplied in a number of ways:

setKey(0); // no signal emitted setKey(QKeySequence()); // no signal emitted setKey(0x3b1); // Greek letter alpha setKey(Qt::Key_D); // 'd', e.g. to delete setKey('q'); // 'q', e.g. to quit setKey(Qt::CTRL + Qt::Key_P); // Ctrl+P, e.g. to print document setKey("Ctrl+P"); // Ctrl+P, e.g. to print document

By default, this property contains an empty key sequence.

Access functions:

QKeySequence key() const
void setKey(const QKeySequence &key)

pub unsafe fn set_whats_this(&mut self, text: impl CastInto<Ref<QString>>)[src]

This property holds the shortcut's "What's This?" help text

Calls C++ function: void QShortcut::setWhatsThis(const QString& text).

C++ documentation:

This property holds the shortcut's "What's This?" help text

The text will be shown when the application is in "What's This?" mode and the user types the shortcut key() sequence.

To set "What's This?" help on a menu item (with or without a shortcut key), set the help on the item's action.

By default, this property contains an empty string.

Access functions:

QString whatsThis() const
void setWhatsThis(const QString &text)

See also QWhatsThis::inWhatsThisMode() and QAction::setWhatsThis().

pub unsafe fn static_meta_object() -> Ref<QMetaObject>[src]

Returns a reference to the staticMetaObject field.

pub unsafe fn tr(
    s: impl CastInto<Ptr<c_char>>,
    c: impl CastInto<Ptr<c_char>>,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QShortcut::tr(const char* s, const char* c, int n).

pub unsafe fn tr_utf8(
    s: impl CastInto<Ptr<c_char>>,
    c: impl CastInto<Ptr<c_char>>,
    n: c_int
) -> CppBox<QString>
[src]

Calls C++ function: static QString QShortcut::trUtf8(const char* s, const char* c, int n).

pub unsafe fn whats_this(&self) -> CppBox<QString>[src]

This property holds the shortcut's "What's This?" help text

Calls C++ function: QString QShortcut::whatsThis() const.

C++ documentation:

This property holds the shortcut's "What's This?" help text

The text will be shown when the application is in "What's This?" mode and the user types the shortcut key() sequence.

To set "What's This?" help on a menu item (with or without a shortcut key), set the help on the item's action.

By default, this property contains an empty string.

Access functions:

QString whatsThis() const
void setWhatsThis(const QString &text)

See also QWhatsThis::inWhatsThisMode() and QAction::setWhatsThis().

Trait Implementations

impl Deref for QShortcut[src]

type Target = QObject

The resulting type after dereferencing.

fn deref(&self) -> &QObject[src]

Calls C++ function: QObject* static_cast<QObject*>(QShortcut* ptr).

impl DerefMut for QShortcut[src]

fn deref_mut(&mut self) -> &mut QObject[src]

Calls C++ function: QObject* static_cast<QObject*>(QShortcut* ptr).

impl StaticUpcast<QObject> for QShortcut[src]

unsafe fn static_upcast(ptr: Ptr<QShortcut>) -> Ptr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QShortcut* ptr).

unsafe fn static_upcast_mut(ptr: MutPtr<QShortcut>) -> MutPtr<QObject>[src]

Calls C++ function: QObject* static_cast<QObject*>(QShortcut* ptr).

impl StaticDowncast<QShortcut> for QObject[src]

unsafe fn static_downcast(ptr: Ptr<QObject>) -> Ptr<QShortcut>[src]

Calls C++ function: QShortcut* static_cast<QShortcut*>(QObject* ptr).

unsafe fn static_downcast_mut(ptr: MutPtr<QObject>) -> MutPtr<QShortcut>[src]

Calls C++ function: QShortcut* static_cast<QShortcut*>(QObject* ptr).

impl DynamicCast<QShortcut> for QObject[src]

unsafe fn dynamic_cast(ptr: Ptr<QObject>) -> Ptr<QShortcut>[src]

Calls C++ function: QShortcut* dynamic_cast<QShortcut*>(QObject* ptr).

unsafe fn dynamic_cast_mut(ptr: MutPtr<QObject>) -> MutPtr<QShortcut>[src]

Calls C++ function: QShortcut* dynamic_cast<QShortcut*>(QObject* ptr).

impl CppDeletable for QShortcut[src]

unsafe fn delete(&mut self)[src]

Destroys the shortcut.

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

C++ documentation:

Destroys the shortcut.

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]