6.0.0-rc4Source

QKeySequenceEdit Class

The QKeySequenceEdit class lets the user enter a key sequence, such as a shortcut. More…

Header#include <QKeySequenceEdit>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget

List of all members, including inherited members

Public Functions

QKeySequenceEdit(QWidget *parent = nullptr)
QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent = nullptr)
~QKeySequenceEdit()
QKeySequencekeySequence() const
voidsetClearButtonEnabled(bool enable)
boolisClearButtonEnabled() const

Reimplemented Public Functions

QSizesizeHint() const

Public Slots

voidsetKeySequence(const QKeySequence &keySequence)
voidclear()

Signals

voideditingFinished()
voidkeySequenceChanged(const QKeySequence &keySequence)

Reimplemented Protected Functions

boolevent(QEvent *event)
voidkeyPressEvent(QKeyEvent *event)
voidkeyReleaseEvent(QKeyEvent *event)
voidfocusOutEvent(QFocusEvent *event)
voidresizeEvent(QResizeEvent *event)

Detailed Description

The edit shows the key sequence. When it has the focus, the next key the user presses, with its modifiers, becomes the key sequence, and editingFinished() follows a moment later:

auto *edit = new QKeySequenceEdit(action->shortcut(), dialog);
connect(edit, &QKeySequenceEdit::editingFinished, [=] { action->setShortcut(edit->keySequence()); });

See also QKeySequence and QAction::setShortcut().

Differences from Qt

A key sequence of Nt has one key, so the edit records one key with its modifiers rather than up to four, and there is no maximumSequenceLength() or finishingKeyCombinations(). The clear button setting is recorded but no button is shown.

Member Function Documentation

[explicit] QKeySequenceEdit::QKeySequenceEdit(QWidget *parent = nullptr)

Constructs an empty key sequence edit with the given parent.

[explicit] QKeySequenceEdit::QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent = nullptr)

Constructs a key sequence edit with the given keySequence and parent.

[override] QKeySequenceEdit::~QKeySequenceEdit()

Destroys the edit.

[slot] void QKeySequenceEdit::clear()

Clears the key sequence.

[signal] void QKeySequenceEdit::editingFinished()

This signal is emitted when the user has finished entering the key sequence: a moment after the last key, or when the edit loses the focus.

[override, protected] bool QKeySequenceEdit::event(QEvent *event)

Reimplements QWidget::event().

Tab and Shift+Tab are recorded too, rather than moving the focus.

[override, protected] void QKeySequenceEdit::focusOutEvent(QFocusEvent *event)

Reimplements QWidget::focusOutEvent().

bool QKeySequenceEdit::isClearButtonEnabled() const

Returns whether the edit shows a clear button. The default is false.

[override, protected] void QKeySequenceEdit::keyPressEvent(QKeyEvent *event)

Reimplements QWidget::keyPressEvent().

A key that is not a modifier, with the modifiers that are held, becomes the key sequence.

[override, protected] void QKeySequenceEdit::keyReleaseEvent(QKeyEvent *event)

Reimplements QWidget::keyReleaseEvent().

QKeySequence QKeySequenceEdit::keySequence() const

Returns the key sequence.

See also setKeySequence().

[signal] void QKeySequenceEdit::keySequenceChanged(const QKeySequence &keySequence)

This signal is emitted when the key sequence changes to keySequence.

[override, protected] void QKeySequenceEdit::resizeEvent(QResizeEvent *event)

Reimplements QWidget::resizeEvent().

void QKeySequenceEdit::setClearButtonEnabled(bool enable)

Sets whether the edit shows a button that clears it to enable; recorded only.

[slot] void QKeySequenceEdit::setKeySequence(const QKeySequence &keySequence)

Sets the key sequence to keySequence and emits keySequenceChanged() if it changes.

See also keySequence().

[override] QSize QKeySequenceEdit::sizeHint() const

Reimplements QWidget::sizeHint().