Skip to content

KeySequenceEdit

Base classes

Name Children Inherits
WidgetMixin
prettyqt.widgets.widget
QKeySequenceEdit
PySide6.QtWidgets
QKeySequenceEdit(self, /, parent: PySide6.QtWidgets.QWidget | None \= None, *, keySequence: PySide6.QtGui.QKeySequence | None \= None, clearButtonEnabled: bool | None \= None, maximumSequenceLength: int | None \= None, finishingKeyCombinations: collections.abc.Sequence[PySide6.QtCore.QKeyCombination] | None \= None) -> None

⋔ Inheritance diagram

graph TD
  2377397968["widgets.KeySequenceEdit"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  1682701161["QtWidgets.QKeySequenceEdit"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  829357528 --> 2377397968
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  1682701161 --> 2377397968
  3620195106 --> 1682701161
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: WidgetMixin, QKeySequenceEdit

Allows to input a QKeySequence.

Source code in prettyqt/widgets/keysequenceedit.py
class KeySequenceEdit(widgets.WidgetMixin, widgets.QKeySequenceEdit):
    """Allows to input a QKeySequence."""

    value_changed = core.Signal(gui.QKeySequence)

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.keySequenceChanged.connect(self._on_value_change)
        self.setClearButtonEnabled(True)

    def __repr__(self):
        return get_repr(self, self.get_value())

    def _on_value_change(self, val):
        self.value_changed.emit(val)

    def set_value(self, value: str | gui.QKeySequence):
        if isinstance(value, str):
            value = gui.KeySequence.fromString(value)
        self.setKeySequence(value)

    def get_value(self) -> gui.QKeySequence:
        return self.keySequence()

    def is_valid(self) -> bool:
        return True

    def get_finishing_key_combinations(self) -> list[core.KeyCombination]:
        return [core.KeyCombination(i) for i in self.finishingKeyCombinations()]

    def get_key_combinations(self) -> list[core.KeyCombination]:
        # QKeySequence is iterable at runtime (not in the stubs)
        keys = self.keySequence()
        return [core.KeyCombination(i) for i in keys]  # ty: ignore[not-iterable]

:fa-brands-github: Show source on GitHub