QKeySequenceEdit Class

The QKeySequenceEdit widget allows to input a QKeySequence. More...

Header: #include <QKeySequenceEdit>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
Since: Qt 5.2
Inherits: QWidget

Properties

Public Functions

QKeySequenceEdit(const QKeySequence &keySequence, QWidget *parent = nullptr)
QKeySequenceEdit(QWidget *parent = nullptr)
virtual ~QKeySequenceEdit()
QList<QKeyCombination> finishingKeyCombinations() const
bool isClearButtonEnabled() const
QKeySequence keySequence() const
qsizetype maximumSequenceLength() const
void setClearButtonEnabled(bool enable)
void setFinishingKeyCombinations(const QList<QKeyCombination> &inishingKeyCombinations)

Public Slots

void clear()
void setKeySequence(const QKeySequence &keySequence)
void setMaximumSequenceLength(qsizetype count)

Signals

void editingFinished()
void keySequenceChanged(const QKeySequence &keySequence)

Reimplemented Protected Functions

virtual bool event(QEvent *e) override
virtual void focusOutEvent(QFocusEvent *e) override
virtual void keyPressEvent(QKeyEvent *e) override
virtual void keyReleaseEvent(QKeyEvent *e) override
virtual void timerEvent(QTimerEvent *e) override

Detailed Description

This widget lets the user choose a QKeySequence, which is usually used as a shortcut. The recording is initiated when the widget receives the focus and ends one second after the user releases the last key.

See also QKeySequenceEdit::keySequence.

Property Documentation

[since 6.4] clearButtonEnabled : bool

This property holds whether the key sequence edit displays a clear button when it is not empty.

If enabled, the key sequence edit displays a trailing clear button when it contains some text, otherwise the line edit does not show a clear button (the default).

This property was introduced in Qt 6.4.

Access functions:

bool isClearButtonEnabled() const
void setClearButtonEnabled(bool enable)

[since 6.5] finishingKeyCombinations : QList<QKeyCombination>

This property holds the list of key combinations that finish editing the key sequences.

Any combination in the list will finish the editing of key sequences. All other key combinations can be recorded as part of a key sequence. By default, Qt::Key_Tab and Qt::Key_Backtab will finish recording the key sequence.

This property was introduced in Qt 6.5.

Access functions:

QList<QKeyCombination> finishingKeyCombinations() const
void setFinishingKeyCombinations(const QList<QKeyCombination> &inishingKeyCombinations)

keySequence : QKeySequence

This property contains the currently chosen key sequence.

The shortcut can be changed by the user or via setter function.

Note: If the QKeySequence is longer than the maximumSequenceLength property, the key sequence is truncated.

Access functions:

QKeySequence keySequence() const
void setKeySequence(const QKeySequence &keySequence)

Notifier signal:

void keySequenceChanged(const QKeySequence &keySequence)

[since 6.5] maximumSequenceLength : qsizetype

This property holds the maximum sequence length.

The value is clamped to [1-4] inclusive, i.e. the maximum value of the maximum sequence length is 4 driven by QKeySequence. The minimum value is 1, which can be useful for single sequence, like a typical shortcut.

The QKeySequence stored in QKeySequenceEdit is truncated if longer than the value of this property.

This property was introduced in Qt 6.5.

Access functions:

qsizetype maximumSequenceLength() const
void setMaximumSequenceLength(qsizetype count)

Member Function Documentation

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

Constructs a QKeySequenceEdit widget with the given keySequence and parent.

QKeySequenceEdit::QKeySequenceEdit(QWidget *parent = nullptr)

Constructs a QKeySequenceEdit widget with the given parent.

[slot] void QKeySequenceEdit::clear()

Clears the current key sequence.

[signal] void QKeySequenceEdit::editingFinished()

This signal is emitted when the user finishes entering the shortcut.

Note: there is a one second delay before releasing the last key and emitting this signal.

[virtual] QKeySequenceEdit::~QKeySequenceEdit()

Destroys the QKeySequenceEdit object.

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

Reimplements: QWidget::event(QEvent *event).

[override virtual protected] void QKeySequenceEdit::focusOutEvent(QFocusEvent *e)

Reimplements: QWidget::focusOutEvent(QFocusEvent *event).

[override virtual protected] void QKeySequenceEdit::keyPressEvent(QKeyEvent *e)

Reimplements: QWidget::keyPressEvent(QKeyEvent *event).

[override virtual protected] void QKeySequenceEdit::keyReleaseEvent(QKeyEvent *e)

Reimplements: QWidget::keyReleaseEvent(QKeyEvent *event).

[override virtual protected] void QKeySequenceEdit::timerEvent(QTimerEvent *e)

Reimplements: QObject::timerEvent(QTimerEvent *event).

© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.